[SOLVED]Health bar problem :P

Alright I haven’t been here for awhile.
I was trying to make games in C++ but learned that I find Java much more easier and entertaining.
So i have this problem with the health bar. It seems every time it gets “hit” or if 1+ is subtracted from the total health, it always makes itself equal to 0.

Here is the one piece of code that I am sure is causing the problem:

g2d.fillRect(610,80,25,Math.round(500 * (CurrentWave.getHealth() / 3000)));

3000 is the total health.
500 is the height of the rectangle.

I tried adding the health bar to the enemy and same problem occurs. I have no idea why the rectangle’s height is changed to 0 every time a number is subtracted from it.

Please help, thank you…
:"D

Looks like a rounding issue with ints. If CurrentWave.getHealth() returns an int then dividing it by 3000 will give you 0. Changing 3000 to 3000f should fix the issue. If it doesn’t try also casting your getHealth() to float).

Thank you, you have fixed the problem.
I never expected a reply so quickly. THANK YOU.
:smiley: