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

2014/12/11

Hp Bar

DiplomatikCow DiplomatikCow

2014/12/11

#
I know there must be a lot of these out there but I am going to post one anyways. I made 11 images in paint, showing a health bar that gets drained by ten for each photo (photo 1 has 100 health, photo 11 has 0). I want to make it so that every time an enemy hits the tower, the HP bar switches to the next image in order to show the damage dealt and health remaining. Someone please help me with this as I do not know how to do this.
danpost danpost

2014/12/11

#
Name your images the same except for a number at the end of the body. For example: "hp0.png", "hp1.png", etc., with image 0 as the full 100 health image. Using a counter to count the number of hits, you can adjust the image easily with 'setImage("hp"+hits+".png");' or something like that.
DiplomatikCow DiplomatikCow

2014/12/11

#
As in implement the counter class? I havent worked much with counters
danpost danpost

2014/12/11

#
When I said 'use a counter', I mean an instance int field that holds a numeric value -- not a counter class.
DiplomatikCow DiplomatikCow

2014/12/11

#
ohhhh, alright, ill go try this out.
danpost danpost

2014/12/11

#
You will need to create a new Actor subclass and place the field in it and add methods for controlling the value and setting its image.
DiplomatikCow DiplomatikCow

2014/12/11

#
I have the private images stored in a class called FortressHealth, but I haven't put any code into it so far, that would work right?
danpost danpost

2014/12/11

#
DiplomatikCow wrote...
I have the private images stored in a class called FortressHealth, but I haven't put any code into it so far, that would work right?
Yes, that should work.
You need to login to post a reply.