Healthbar problem

Hello,

I have a health bar in my game and are where health bar should be displayed is 197 px long. So my health bar, no matter how much health I have, must fit in there ( like in World of Warcraft ). I need to get the width. I tried like this:

new Rect( x, y, 197 * (curHealth / maxHealth), height);

It’s not working. When you have max health it’s working when you don’t it’s 0.

Best regards,
Ivan

The issue is that you are using integer division. Any fraction less than 1 in your code gets truncated to 0. Make curHealth and maxHealth floating point variables, or cast them to floats and your problem will be fixed.