Best Way to Handle Animation States

I’m working on a simple game.  It will be turn based with some complex animation sequences.  I was wondering the best way to handle multiple animations in a row, instead of setting and unsetting event listeners?

Currently my code is filled with if/then and then setting and unsetting timere and event listeners for simple animations.  I’n impactJs there is a state machine and in Jquery you can stack animations and functions on top of themselves, not sure if this is possible in Corona.  I come from the JS world, so I always fall back to that way of thinking.

Example of actions:

Hero run towards Villain 

When hero collides show attack animation

Show Villain hurt animation

Hero End attach animation

Hero turns around

Hero Runs to start position

Villain shows recover animation

Both set to idle animation

Hi @stillen,

I think for this, you’ll need to use sprite event “ended” phases/listeners. It would be quite difficult to sync the animations using timers. Did you read through the tutorial on sprites yet? This shows how to use the different phases and sequences.

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/#topic6

Best regards,

Brent

Personally, I think you’ve answered your own question - this setup is ideal for a Finite State Machine. Check out Jesse Warden’s post on this, very informative:

http://jessewarden.com/2012/07/finite-state-machines-in-game-development.html

Particularly example 2 & 3…

Good to know I’m on the right path,  to me it seemed like the code was getting really long and complicated, for a simple task.  I think I need to refactor out the common parts so it’s easier to follow and read.

Hi @stillen,

I think for this, you’ll need to use sprite event “ended” phases/listeners. It would be quite difficult to sync the animations using timers. Did you read through the tutorial on sprites yet? This shows how to use the different phases and sequences.

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/#topic6

Best regards,

Brent

Personally, I think you’ve answered your own question - this setup is ideal for a Finite State Machine. Check out Jesse Warden’s post on this, very informative:

http://jessewarden.com/2012/07/finite-state-machines-in-game-development.html

Particularly example 2 & 3…

Good to know I’m on the right path,  to me it seemed like the code was getting really long and complicated, for a simple task.  I think I need to refactor out the common parts so it’s easier to follow and read.