## AS: Linear Increasment

• 3,251 Views
• 10 Replies
Inglor
Inglor
• Member since: Jan. 26, 2003
• Offline.
Forum Stats
Member
Level 17
Blank Slate
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

Inglor
Inglor
• Member since: Jan. 26, 2003
• Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Linear Increasment 2005-06-28 14:06:16

oops, forgot :P

AS: main

noob-toast
noob-toast
• Member since: May. 18, 2004
• Offline.
Forum Stats
Member
Level 08
Blank Slate
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.

GeoKureli
GeoKureli
• Member since: Apr. 1, 2003
• Offline.
Forum Stats
Supporter
Level 19
Game Developer
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

noob-toast
noob-toast
• Member since: May. 18, 2004
• Offline.
Forum Stats
Member
Level 08
Blank Slate
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.

onnet5
onnet5
• Member since: Sep. 20, 2005
• Offline.
Forum Stats
Member
Level 02
Blank Slate
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?

dELtaluca
dELtaluca
• Member since: Apr. 16, 2004
• Offline.
Forum Stats
Member
Level 20
Blank Slate
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

shazwoogle
shazwoogle
• Member since: Sep. 27, 2004
• Offline.
Forum Stats
Member
Level 11
Blank Slate
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

GeoffCLogan
GeoffCLogan
• Member since: Apr. 25, 2004
• Offline.
Forum Stats
Member
Level 11
Blank Slate
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?

Newsdee
Newsdee
• Member since: Jan. 21, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
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. :-)

Newsdee
Newsdee
• Member since: Jan. 21, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
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)