An interactive story of love and adventure3.97 / 5.00 14,786 Views
Turn-based PvP Arena Battler3.83 / 5.00 8,146 Views
THE WORLD HAS BEEN INVADED BY ALIENS! It's up to a nerdy, lazy high school kid to save it!3.81 / 5.00 7,640 Views
let's say you have a lifebar, whose max width is 300 and it's min width is 30, now you want that life bar's width to be equal to the right amount each time of life, your problam is, life goes between 10 and 37 :P
This is how it's done:
so basically you have 2 min values, 30 and 10, that's your first 'point.'
you also have 2 max values, 300 and 37, that's your second 'point'
in math, there is only 1 streight line between two points, our points are (10,30) and (37,300), remmember the first value is the variable (life) and the second variable is the function (the stuff you want to change according to the first value)
you can find the angle of a line with this formula (y2-y1)/(x2-x1), in our case (300-30)/(37-10),
this is 270/27, which is 10 ;) so we now know that we must increase the width by 10 for every hp.
now let's make this into a formula
remmember adding a check for hp>10, otherwise you're off limit
hope I helped, post questions
Hey Inglor, I found a different way to do it, and I find it a bit easier to understand. I'm not saying your way is bad, but I am saying it's a bit confusing, but then again, I'm more or a listener, not a reader.
I don't understand. Why is there a y and x axis when a healthbar only goes one way...and what's with the m?
At 11/15/05 02:08 AM, shazwoogle wrote: what i use it just a simple percentage formula leant in grade 8 =P
I just use xscale with a moved registration point. Am I a bad person?
I was going to post a formula based on percentage but I ended up finding the same as Inglor.
Basically the slop of the curve in his post is the percentage (hp %), that is then applied to the second range (the lifebar). Here's the proof:
maxLife = 37
minLife = 10
if hp = 10 -> 0% width
if hp = 37 -> 100% width
width% = (hp - minLife)/(maxLife - minLife)
width% = (hp - 10)/(37-10)
lifeBar._width = width% * (maxBar - minBar) + minBar
lifeBar._width = (hp - 10)/(37-10) * 270 + 30
lifeBar._width = (hp-10)/27 * 270 + 30
lifeBar._width = (hp-10)*10 + 30
lifeBar._width = 10*hp - 100 + 30 (Inglor's formula above)
And here's the generic formula (regardless of values used):
_width = (hp - minLife)/(maxLife - minLife) * (maxBar - minBar) + minBar
_width = (hp - minLife) * (maxBar - MinBar)/(maxLife-minLife) + minBar
_width = (hp - minLife) * [angle of line] + minBar
Where [angle of line] is (maxBar - minBar)/(maxLife - minLife)