Discord
Login
Community
DARK THEME

How to change sprite animation depending on direction

Hey. This is my first time using this. Or making any game and code in general. I was just wondering how to change the animation or sprite whenever the character moves. I already have the animations set out for the directions, I just can't figure out how to make it so that they play whenever the corresponding button is pressed.

https://microstudio.dev/i/gilles/spriteanimation/

If your player is a class it is best to replace the sprite that is to be drawn.

Player = class
  constructor = function( )
     left = sprites["player_walk_left"]
     right = sprites["player_walk_right"]
     ....
     draw_sprite = left
     direct_x = -1
  end

  update = function()
    if keyboard.LEFT then 
       draw_sprite = left
       dirext_x = -1
    end
    if keyboard.RIGHT then 
       draw_sprite = right
       dirext_x = 1
    end
  .....
  end
  
  draw = function()
    screen.drawSprite( draw_sprite, x, y , ..... )
  end
end

What do you mean by "class"? I'm sorry, I'm still new to all this stuff.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community