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.

At the moment I have a simple static texture. Now I want to animate my sprite. The texture is a simple human. When the user press the enter button, the human gets into state2. This is the standart state during gameplay. If the user presses now "space" the sprite should get into state4(4th texture). This would be very unsmooth, so I decided to make a State3(ist just displayed very short to make the animation smooth). Now the sprite is in state4. If the user now releas the "space"-key the sprite should return into State2. For smoothness there is State3 short between.

I use XNA. I have 4 states:

State1 press enter" --> State2 --- "press space" --> (short State3 for smoothness) --> State4 --> "release space" --> (short State3) --> State2

I hope you understand what I mean.

How can I solve this animation? Should I change the texture of the sprite?

share|improve this question
1  
You're going to have to try and describe the problem a little better. If the problem is State3 is activating twice, don't activate it on release of space. –  Byte56 Feb 11 '13 at 20:39
    
You've described a situation. It's not clear whether that's the situation you want (in which case, tell us what you already have), or it's what you have (in which case you should tell us what you want to change about it). –  Kevin Reid Feb 12 '13 at 4:56
    
Okey sry :/ At the moment I have a simple static texture. Now I want to animate my sprite. The texture is a simple human. When the user press the enter button, the human gets into state2. This is the standart state during gameplay. If the user presses now "space" the sprite should get into state4(4th texture). This would be very unsmooth, so I decided to make a State3(ist just displayed very short to make the animation smooth). Now the sprite is in state4. If the user now releas the "space"-key the sprite should return into State2. For smoothness there is State3 short between. –  user26188 Feb 12 '13 at 10:39
    
So what's the actual problem? Do you not want it to enter State3 after releasing the space bar? –  Byte56 Feb 13 '13 at 0:05
    
yeah my problem is, that State3 should just be displayed for a very short time. –  user26188 Feb 13 '13 at 11:02
add comment

1 Answer

Add a timer for transition between states and then decrease the time during state3. For examples:

enum State
     {
        state1,
        state2,
        state3,
        state4
     }


float timer;

// Your game loop update function
void Update()
{
   switch(state)
   {
      case State.state3:
           timer -= Time.detlaTime; // delta between frames in miliseconds
           if(timer <= 0)
           {
              state = State.state4;
           }
           break;
           /* Your 
           *  logic
           *  here
           */
share|improve this answer
add comment

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.