Help [HELP][Rm2k] Using a picture for a health bar (Read 448 times)

  • Avatar of Mikemc
  • Caboose
  • PipPipPip
  • Group: Premium Member
  • Joined: Oct 7, 2002
  • Posts: 387
I have a health bar 2 pixels by 100 pixels. I want it to move left according to the percentage of your health, which is a custom value (although it could be your health is that would be simpler). Currently when you get hit, an amount is subtracted, and then your current HP is divided by your max HP, and then multiplied by 100 to get the percentage. However what seems to be happening is after the division the number would be a decimal and the player is instantly killed.

What is the easiest way to do a single health bar?

- Mike


Quote from: Evangel
You can't run from your past, S4D. YOU CAN'T RUN FROM YOUR PAST!
  • Comrade!
  • Pip
  • Group: Premium Member
  • Joined: Aug 16, 2004
  • Posts: 111
Multiply by 100 before dividing instead of afterward?
  • Avatar of Mikemc
  • Caboose
  • PipPipPip
  • Group: Premium Member
  • Joined: Oct 7, 2002
  • Posts: 387
No, then I get an even smaller number. Basically I would like a health bar that only measures the percentage of your health and not the actual points.


Quote from: Evangel
You can't run from your past, S4D. YOU CAN'T RUN FROM YOUR PAST!
  • Comrade!
  • Pip
  • Group: Premium Member
  • Joined: Aug 16, 2004
  • Posts: 111
....No???

Current health: 66
Max health: 70

66 * 100 / 70 = 94%

66 / 70 * 100 = 94%

End result is equal, however you no longer end up with a completely decimal number at any of the steps, making it RM friendly o_O
Last Edit: August 06, 2009, 12:12:42 pm by Arias
  • Comrade!
  • PipPipPipPip
  • Group: Member
  • Joined: Sep 1, 2003
  • Posts: 525
Not that it matters, but I've always formatted the the equation like this to save confusion: [length ][/length] * [Current ][/Current] / [Max ][/Max]. It just reminds me that the percentage is used to scale the health bar. Also don't forget that you'll need to add an X offset equal to the position of the health bar when health is at 0, then increment it by the value of the previous equation - otherwise the bar won't line up!
"the way you speak about rm2k3, like "modules, arrays, pointers" sounds like
you're some badass c++ programmer stuck in the past and only has rm2k3 to
work with"
-Gutts
  • Avatar of Mikemc
  • Caboose
  • PipPipPip
  • Group: Premium Member
  • Joined: Oct 7, 2002
  • Posts: 387
....No???
Current health: 66
Max health: 70
66 * 100 / 70 = 94%
66 / 70 * 100 = 94%
Huh.. I kept getting 0.0055 (55/100) oh well, thanks you two!


Quote from: Evangel
You can't run from your past, S4D. YOU CAN'T RUN FROM YOUR PAST!
  • god damn it man-o-war god damn it
  • PipPipPipPipPipPipPip
  • Group: Member
  • Joined: Apr 15, 2008
  • Posts: 1133
Huh.. I kept getting 0.0055 (55/100) oh well, thanks you two!
That's actually 55/10000... Something is going wrong with your maths (or you made a typo)

You could also try doing all this to a dummy variable and then making the actual life the final product, instead of toying with the life itself
don't mind me, just postin' after a few brewskies
somebody’s Barkley --- could be another’s Monopolo.