Be a Supporter!

AS: Linear Increasment

  • 3,204 Views
  • 10 Replies
New Topic Respond to this Topic
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
AS: Linear Increasment Jun. 28th, 2005 @ 02:04 PM Reply

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 Jun. 28th, 2005 @ 02:06 PM Reply

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 Aug. 29th, 2005 @ 12:04 AM Reply

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
GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Linear Increasment Aug. 29th, 2005 @ 12:56 AM Reply

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 Aug. 29th, 2005 @ 01:23 AM Reply

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
onnet5
onnet5
  • Member since: Sep. 20, 2005
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Linear Increasment Oct. 23rd, 2005 @ 01:34 PM Reply

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 Oct. 23rd, 2005 @ 03:40 PM Reply

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
shazwoogle
shazwoogle
  • Member since: Sep. 27, 2004
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Linear Increasment Nov. 15th, 2005 @ 02:08 AM Reply

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 Nov. 15th, 2005 @ 03:04 AM Reply

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 Nov. 15th, 2005 @ 03:16 AM Reply

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 Nov. 15th, 2005 @ 03:23 AM Reply

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)