00:00
00:00

AS: Linear Increasment

3,870 Views | 10 Replies
New Topic Respond to this Topic

AS: Linear Increasment 2005-06-28 14:04:56


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
y-y1=m(x-x1);
so y-30=10(x-10);
lifebar._width=10*hp-100+30;
remmember adding a check for hp>10, otherwise you're off limit

hope I helped, post questions

Response to AS: Linear Increasment 2005-06-28 14:06:16


oops, forgot :P

AS: main

Response to AS: Linear Increasment 2005-08-29 00:04:33


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.


These new signatures can suck on mah balls. My lolis don't fit in. Lol wut what are you guys still doing on NG, move on.

BBS Signature

Response to AS: Linear Increasment 2005-08-29 00:56:21


At 8/29/05 12:04 AM, KinZo wrote: grr inglor = bad. i found better way. but i wont tell you because i have an itchy vagina

the quote says how i feel


This blog I made | This game sucks | I, twit

Just trying to get enough Twitter followers to quit Facebook forever

Response to AS: Linear Increasment 2005-08-29 01:23:55


Someone's unhappy. :( Here is some good news though. I hope.


These new signatures can suck on mah balls. My lolis don't fit in. Lol wut what are you guys still doing on NG, move on.

BBS Signature

Response to AS: Linear Increasment 2005-10-23 13:34:41


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?

Response to AS: Linear Increasment 2005-10-23 15:40:35


At 10/23/05 01:34 PM, onnet5 wrote: 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?

lol @ you


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature

Response to AS: Linear Increasment 2005-11-15 02:08:43


what i use it just a simple percentage formula leant in grade 8 =P

A/B*100

Response to AS: Linear Increasment 2005-11-15 03:04:30


At 11/15/05 02:08 AM, shazwoogle wrote: what i use it just a simple percentage formula leant in grade 8 =P

A/B*100

I just use xscale with a moved registration point. Am I a bad person?

Response to AS: Linear Increasment 2005-11-15 03:16:16


Hah, pwned.
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)

QED. :-)

Response to AS: Linear Increasment 2005-11-15 03:23:15


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)