Triggering State Changes with Health Counter
Posted
by
Hairgami_Master
on Game Development
See other posts from Game Development
or by Hairgami_Master
Published on 2012-11-24T14:30:31Z
Indexed on
2012/11/24
17:19 UTC
Read the original article
Hit count: 170
game-loop
I'm developing a game where the player changes states as their health decreases. Below 50, it should trigger animation1. Below 30, it should trigger animation2.
The problem is, I only want to trigger animation1 once. But my game timer is checking every "frame", so it's triggering animation1 every cycle below 50. I only want it to trigger once, then not again until it's gone over 50 and then naturally decreased back to below 50.
Are there any tried and true strategies for triggering state changes as a timer counts down (without the over-triggering problem)?
I thought I could say:
if (health == 50)
animation1.play();
but sometimes, health never equals exactly 50, so it will skip right past that statement.
© Game Development or respective owner