How do you handle animations that are for transitioning between states?

Posted by yaj786 on Game Development See other posts from Game Development or by yaj786
Published on 2011-06-20T02:08:24Z Indexed on 2011/06/20 16:40 UTC
Read the original article Hit count: 231

Filed under:
|
|

How does one usually handle animations that are for going between a game object's states? For example, imagine a very simple game in which a character can only crouch or stand normally. Currently, I use a custom Animation class like this:

class Animation{
 int numFrames;
 int curFrame;
 Bitmap spriteSheet;
 //... various functions for pausing, returning frame, etc.
}

and an example Character class

class Character{
 int state;
 Animation standAni;
 Animation crouchAni;
 //... etc, etc.
}

Thus, I use the state of the character to draw the necessary animation.

if(state == STATE_STAND)
    draw(standAni.updateFrame());
else if(state == STATE_CROUCH)
    draw(crouchAni.updateFrame());

Now I've come to the point where I want to draw "in-between" animations, because right now the character will just jump immediately into a crouch instead of bending down. What is a good way to handle this? And if the way that I handle storing Animations in the Character class is not a good way, what is?

I thought of creating states like STATE_STANDING_TO_CROUCHING but I feel like that may get messy fast.

© Game Development or respective owner

Related posts about animation

Related posts about sprites