Choose first frame of play_animation?


#1

Is there a way to choose the first frame of an atlas flip-book animation? Here’s my use case:

I have a object who can walk in 4 directions (up,down,left,right). For each of these animations, the first frame is a left foot forward, second frame is right foot forward. If a user is rapidly changing direction, calling msg.post(…,“play_animation”) is going to constantly be resetting to the 1st frame of each animation, so it looks like the object is not really “walking”, but just standing on one leg and changing direction!

What I’d like to do is something like keep track of which frame is going and call something like msg.post(…,“play_animation”, {id = hash(“move_left”), frame=2}). Is there any way to do that, or another suggestion for how to accomplish this?


#2

Would be a nice feature… in the mean time you can use animations as frames and animate between them yourself.


#3

My recommendation would be to keep track of the currently playing animation and perhaps prevent the same animation from being played until the animation has completed (animation_done message). And if you have a separate walk_left and walk_right animation perhaps keep only the one and use sprite.set_hflip() to flip the sprite based on direction of movement.


#4

The problem isn’t with calling the same animation, it’s switching animations. Thanks for the set_hflip(), that would work for switching between left/right but unfortunately not for up/down since they are not just mirror images. I might just need to go with @Pkeod 's suggestion and handle animation frames myself.


#5

Lateral solution: have two animations sets and have each one start at a different point in the cycle.


#6

I think this thread answers my question, but just to confirm:

I have a GO with multiple instances of the same animated sprite. I’d like to start the animation of each of these at a random frame to prevent them from being animated in sync. Is the only/best way to do this to make multiple animations manually?

The animation only has 5 frames so it isn’t much of a problem, but I can see this being problematic in other cases.


#7

Yes, it is the only way to do it currently. (Well, I can think of a really weird way of achieving it but let’s not go down that route… :slight_smile:

See this post for future alternatives: Pixel Art Witchcrafter - RPG Puzzle Story