This site requires JavaScript, please enable it in your browser!
Greenfoot back
Ploppy
Ploppy wrote ...

2012/12/28

Removing Healthbars and adding them

Ploppy Ploppy

2012/12/28

#
Ok so I ran into another Problem. I want to have health in my game, like a health bar. I got 3 pictures each one with the amount of health every time you get hit. Now what I need is the code. In the code I want to remove the first picture of the health bar and put in the second one when I get hit. I don't know how to do this. I know how to put the second one in but I don't know how to remove the first one. This is what I have so far. public void kalb() { if (canSee(Spaceship.class) ) { eat(Spaceship.class); getWorld().addObject(new Spaceship(), 80, 500); (I don't know how to remove the picture of health) (class name is Three) (Adding the second picture of health) (class name is Two) Greenfoot.playSound("EXPLOSAO.mp3"); } } I'd rather not have the spaceship eaten and added though. HELP IS HIGHLY APPRECIATED!! :D
danpost danpost

2012/12/28

#
This only requires one actor class; instead of multiple classes (one for each health level: 'One', 'Two', 'Three', etc.). Put the three pictures in a GreenfootImage array, and as the health decreases, update the image of the object accordingly. This is most easily accomplished by adding a public method that changes the health and updates the image (by setting a new image to the actor object, the old image is removed).
You need to login to post a reply.