hello someone knows how to make a life bar that is spent slowly.
if anyone knows please send me the code
private static final int MAX_HEALTH = 20; private int health = MAX_HEALTH; private int pixelsPerHealthPoint = healthBarWidth / MAX_HEALTH;
// time period (in frames) for losing one health point (higher values = slower decrease in health) private static final LOSE_HEALTH_PERIOD = 60;
// Frames run since the last health loss
private int currentFrame = 0;
public void act() {
checkForHealthLoss();
}
private void checkForHealthLoss() {
++currentFrame;
if (currentFrame == LOSE_HEALTH_PERIOD) {
this.loseHealth();
currentFrame = 0;
}
}