-1
\$\begingroup\$

I'm trying to make a working duck animation but the animation keeps looping, how do I make it so that the duck animation freezes on a sertain frame?

Right now I use a variable to loop it so that it loads the animation over and over, but I want it to pause at the last frame at the moment the animation looks like this :

if (elapsed >= delay) {
    else if (count < 3 && twoFrames == true) { 
        frames++; 
        count++; 
    } 
    elapsed = 0; 
    if (twoFrames == true) {
         sourceDuck = new Rectangle(50 * ducklist[frames], 0, 50, 43); 
    } 

Delay is set to 90f

\$\endgroup\$
2
  • 2
    \$\begingroup\$ You provide very little(none at all) detail about how you currently handle the animation. Some details regarding your implimentation would be really helpfull. You can track if the animation needs to update every frame with a variable, which you can check each frame before updating the texture on the duck. If the variable is set to not update, you don't update and that stops the animation, maybe. \$\endgroup\$ Dec 1, 2014 at 12:15
  • \$\begingroup\$ Right now I use a variable to loop it so that it loads the animation over and over, but I want it to pause at the last frame at the moment the animation looks like this : if (elapsed >= delay) { else if (count < 3 && twoFrames == true) { frames++; count++; } elapsed = 0; if (twoFrames == true) { sourceDuck = new Rectangle(50 * ducklist[frames], 0, 50, 43); } Delay is set to 90f. \$\endgroup\$
    – user55613
    Dec 1, 2014 at 12:40

1 Answer 1

0
\$\begingroup\$

I would advise against coming up with your own logic like pausing at the last frame of animation, or such if you plan on doing more animations later. I've done this when I started and it can very quickly go out of hand.

You could accomplish this with a state machine. This is a simple yet very easily customizable way of doing animations in case you implement it well. This is used very often in game development. For example, you define a start state, "idle" where the standing animation plays. From there you could go into several states which have different rewuirements. For example, the ducking state has a requirement of inputting the down key. You could create three states: duckStart, duck, duckEnd.

DuckStart state: from idle state you could go to this state if you input down key (just an example). The animation where the character goes from standing, to ducking animation plays.

Duck state: you can go to this state, from duckStart state if the duckStart animation reached its last frame and you are still pressing down key.

DuckEnd state: you can go to this state from duckStart state, or the duck state if you cancel the down key press.

You could look up Finite State Machines for further information.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .