is there a way to add a movement with an animation in all of the sides
can you help me I need to have an animated movement of the character only when walking and without having to do more than one
can you help me I need to have an animated movement of the character only when walking and without having to do more than one
It requires a bit of code... In general, keep the current state of your character in a variable isMoving = false
.
Prepare an animated sprite of the character with walking animation.
In update, when a character is moving (when it changes position) set isMoving = true
. When the character stops, set isMoving = false
.
In draw, depending on the value of isMoving
, you display the whole animation, or just a single frame - one that best represents the character's idle stance.
if isMoving then
screen.drawSprite("charMoveSprite", 0, 0, 50, 50) // displays whole animation
else
screen.drawSprite("charMoveSprite.0", 0, 0, 50, 50) // displays ONLY first frame of the animation
end
As for the second part of your question - it's not possible in most cases. You always need to do at least half of your animation sprites.
It's possible to programmatically mirror an animated sprite, so if you do all "go right" animations, you can get "go left" by mirroring.
To mirror sprite, you can use screen.setDrawScale(-1,1)
.
There's an exception, though - if your game is presented from exactly top-down perspective, then you can get by with just a single animation.
You can use screen.setDrawRotation()
method to rotate characters to the desired direction, then and play the same "walk forward" animation.
All that is assuming you're asking about 2D game. For 3D it's quite possible, but requires A LOT of explaining (like everything in 3D ;) )