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);
}
}
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);
}
for (Lava l: lava)
if (player.getHitbox().intersects(l.hitbox)) {
player.setInLava(true);
player.playerDeathAndGameOver();
player.setInLava(false);
}
2 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @Erky! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@272473391041347585>.

Did you find this page helpful?