I just wonder, how to make one time animation. I have a lot of animations, but they, unfortunately, are repeating in the loop, and that's not what I wanted. Here's some code fragments:
public void act(float delta) {
super.act(delta);
stateTime += Gdx.graphics.getDeltaTime();
TextureRegion currentFrame = activeAnimation.getKeyFrame(stateTime, true);
setDrawable(new TextureRegionDrawable(currentFrame));
}
RUNNING_ANIMATION_BY_SIDE = new Animation<TextureRegion>(0.333f,framesRunningBySide,Animation.PlayMode.LOOP);
SHOOTING_ANIMATION = new Animation<TextureRegion>(0.333f, framesShootingFront, Animation.PlayMode.NORMAL);
STEADY_ANIMATION = new Animation<TextureRegion>(0.230f, framesStandingFront, Animation.PlayMode.LOOP_RANDOM);
DYING_ANIMATION = new Animation<TextureRegion>(0.230f, framesDyingFront,Animation.PlayMode.NORMAL);
setActiveAnimation(STEADY_ANIMATION);
How to make my actor to play animation only one-time? As you see, I've set to DYING_ANIMATION a PlayMode.NORMAL.
You're using overloaded method getKeyFrame(float stateTime, boolean looping)
of Animation
class.
If you pass looping true
as second parameter, your animation playmode will convert from PlayMode.NORMAL
to PlayMode.LOOP
so use getKeyFrame(float stateTime)
or pass false
as second parameter but for STEADY_ANIMATION
playmode will converted from PlayMode.LOOP_RANDOM
to PlayMode.LOOP
.