Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข3y agoโ€ข
3 replies
Erky

In game loop, reset index to 0, go through 4 animations, then do something

can someone help me to show* all 4 images of the dying animation before setting to gameover*? it works for setting game over in the player class but when I try to set game over when walking on a trap (lava), it only shows the first animationindex and I don't know how to correctly show all images of dying and then set game over

Player
public void playerDeathAndGameOver() {
        if (playerAction != DYING) {
            playerAction = DYING;
            animationIndex = 0;
            animationTick = 0;
        }

        if (animationIndex == getSpriteAmount(DYING) - 1) {
            // here we reached final death animation shown, now set game over!
            game.setGameState(GAME_OVER);
        }
    }


ObjectManager:
for (Lava l: lava)
            if (player.getHitbox().intersects(l.hitbox)) {
                player.setInLava(true);
                player.playerDeathAndGameOver();
                player.setInLava(false);
            }
Was this page helpful?