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

2015/9/10

Making a health bar

hoothoot hoothoot

2015/9/10

#
can anyone help me make a health bar where the width is my player's(Gohan.class) health divided by 10,000?
Zamoht Zamoht

2015/9/10

#
You can "steal" mine http://www.greenfoot.org/scenarios/9314. If you need something different you can just download the code and customize it yourself.
hoothoot hoothoot

2015/9/10

#
thanks!
hoothoot hoothoot

2015/9/10

#
how would I hook that up to my player? if my player's health=850000/900000, what commands within the player would I use to change the value on the healthbar?
danpost danpost

2015/9/11

#
Assuming 900000 is the maximum health value then:
int barSize = barWidth*getHealth()/900000;
would give you the amount of the bar that should represent the current value. You can refer to my Value Display Tutorial scenario to see how to apply a bar to your player.
Zamoht Zamoht

2015/9/11

#
If you look at my example you can look at the code I wrote for the buttons. The buttons change the value of the health bar, so you can put that code into your player, so health change triggers on other things than button pressing.
You need to login to post a reply.