Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
libGDX stop animation at last frame

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();
    }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda