i want to create a health bar that slowly disappears piece by piece how do i do that
public GreenfootImage createLifeBar(int leben, int maxLeben)
{
GreenfootImage img = new GreenfootImage(84, 24);
img.setColor(Color.BLACK);
img.fill();
img.setColor(Color.GRAY);
img.fillRect(2, 2, 80, 20);
img.setColor(Color.GREEN);
img.fillRect(2, 2, (int)(80*leben/maxLeben), 20);
GreenfootImage num = new GreenfootImage(leben+"/"+maxLeben, 20, Color.BLACK, new Color(0,0,0,0));
img.drawImage(num, img.getWidth()/2-num.getWidth()/2, 2);
return img;
}private int health, maxHealth;
public HealthBar(int max)
{
maxHealth = max;
health = maxHealth;
setImage(createLifeBar(health, maxHealth));
}
public void act()
{
setImage(createLifeBar(--health, maxHealth));
}