- Home /
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
Answer by robertbu · Apr 17, 2014 at 08:13 PM
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.
Your answer
Follow this Question
Related Questions
Healthbar is over play dead Animation 1 Answer
Enemy HealthBar Problems 2 Answers
How to make my health decrease? 1 Answer
Health Bars in 2D Game 1 Answer
Getting the 2d coordinates of an object 2 Answers