Libgdx Death animation

Hello, I want to make death animation for my character.

Here is a basic example -

stateTime += Gdx.graphics.getDeltaTime();          
currentFrame = deathAnimation.getKeyFrame(stateTime, true);  
spriteBatch.begin();
spriteBatch.draw(currentFrame, 50, 50);            
spriteBatch.end();

So the problem is that the character is looping the animation over and over again.
and I want it to do the animation and stay on the last frame(which is when the character lays on the ground) instead of looping it.

Any ideas?

make a check and see if it is on last frame?

public void doingAnimation(){

   if(frames == 5){
       stopAnimation();
       animation = false;
   }

   //make an int to plus or something
   frames++;

   or
   while(animation){
       frames++;
   }

}

btw just trying to help :slight_smile: hope you get it

There must be more effective way to achieve this…

Try doing this after you create the animation.

deathAnimation.setPlayMode(PlayMode.NORMAL);

I’m not sure if this will draw the last frame once it’s done. If it does, great, but if it doesn’t, you could check to see if it’s finished and then do what you want.

deathAnimation.isAnimationFinished(stateTime);

while(animation){
       frames++;
   }

Don’t do this. Think about what you are doing here.