1
votes

I have class which extends Actor. My animations are in 'act' method with stateTime timer. Below is fragment of this class:

@Override
public void act(float delta) {
    super.act(delta);
    stateTime += delta;

    if(!isDeath) {

       ...

    } else {
        if(!animationDead.isAnimationFinished(stateTime)){
            textureRegion = animationDead.getKeyFrame(stateTime, true);
        }

    }
}

animationDead has PLAYMODE.NORMAL

I'm trying to use '!animationDead.isAnimationFinished(stateTime)' but it's stoping my animation after first frame. I would like to stop animation after last frame.

Also i'm trying to set stateTime = 0; but the same, stopping after first frame.

The same situation i have when i press for example SPACE key my 'actor' should play fight animation. But for all frames of fight animaton i have to hold space key. One tap space is one frame of animation.

Here is fragment of this method:

@Override
public void act(float delta) {
    super.act(delta);
    stateTime += delta;

    if(!isAttacking()) {
    ...

    /* Keyboard events */
    ...
    setAttacking(false);

    if (Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
        setAttacking(true);
        if (moveToRight) {
            textureRegion = animationAttack.getKeyFrame(stateTime,true);
        } else if (!moveToRight) {
            isPlayerFlippedToLeft = true;
            textureRegion = animationAttack.getKeyFrame(stateTime,true);
        }
        setPlayerWidthAndHeight();
    }
1

1 Answers

2
votes

When your call animationDead.getKeyFrame(stateTime, true); method on Animation then Animation's mode is converted into PlayMode.LOOP or PlayMode.LOOP_REVERSED depending upon what's animation mode current have.

PlayMode.NORMAL -> PlayMode.LOOP

PlayMode.REVERSED -> PlayMode.LOOP_REVERSED

isAnimationFinished(stateTime) return true if the animation would be finished if played without looping.

Why don't you call animationAttack.getKeyFrame(stateTime);

EDIT

Ok, now you're using animationAttack.getKeyFrame(stateTime);

You're using same stateTime for three different Animation, when time comes to show animation of animationDead, stateTime crossed animation frameduration and at that time isAnimationFinished(stateTime) return true so

if(!animationDead.isAnimationFinished(stateTime)){  //condition false
   textureRegion = animationDead.getKeyFrame(stateTime); 
}

finally textureRegion having no dead TextureRegion frame.