Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
I found this question: gamedev.stackexchange.com/questions/8537/… . I guess the answer is to push "crouching" then "crouched" to a queue system and have the system decide when to switch from one state to the next. If anyone has any better ideas, I still would like to hear them. –  you786 Jun 20 '11 at 5:40
    
You can, if you decide you have found the solution yourself, post your own solution as an answer (and accept it as well, if nobody posts a better one). Welcome to the site! –  Josh Petrie Jun 20 '11 at 15:42

2 Answers 2

In between states are still states, more in general transient states should be modelled as states if their duration exeedes the frame duration; otherwise one should consider if appropriate on a case by case basis.

share|improve this answer
up vote 3 down vote accepted

If anyone is curious, this is how I ended up implementing it:

USing my example, I got rid of exclusive playerStates, and simply used different boolean flags like isCrouched.

Then I would have something like this in my PlayerObject's update() function

if(isCrouched)
{
    if(currentAnimation == startingCrouchAnimation && startingCrouchAnimation.isFinished())
        currentAnimation = crouchedAnimation;
}

and to draw the animation

draw(currentAnimation.update());
share|improve this answer
    
+1 to Fxlll's answer, I don't see why the between-crouching-and-standing animation needs to be a special case - how is it different from any other animation state? –  BlueRaja - Danny Pflughoeft Jul 4 '11 at 1:56
    
Well I guess it's because my implementation uses the playerState for more than just animation/drawing, it also used it for physics logic. So if I used different states for between-crouching-and-standing and crouching, I would have huge if statements to decide if the player is crouching: if(playerState == betwee..-standing || playerState == crouching || etc. etc.) –  you786 Aug 3 '11 at 22:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.