Guide to easing using this script

P

Pup

Guest
Hey guys! So I got into GameMaker about 2 months ago, my friends be showing me the ropes. I've had some experience in HTML, and I wanted to do easing for a GUI I'm making. Basically I have the slide that gets larger as you get more items. There's 5 positions for it, it has a variable called "point," then "perc_point" point is the current point you are at used for in game stuff. While perc_point is the exact point I am drawing this bar at. I got a script my friend, and I used it to make a transparency ease, but I am struggling to make it ease the movement of the bar. The bar is two directional because you can lose points, and gain points. I got it to half work one way, but not the other.

Here's the transparency ease code: draw_set_alpha(ease("easeoutquad",1-tab_alpha_ani)) tab_alpha_ani+=.175

Here's the ease script:
/// ease(function, x)
/// http://www.easings.net

var function,xx,xx2,xxm1;
function=argument0
xx=argument1
xx2=xx*2
xxm1=xx-1

if (xx<=0)
return 0
if (xx>=1)
return 1

switch (function) {

case "linear":
return xx

case "instant":
return 0

case "easeinquad":
return xx*xx

case "easeoutquad":
return -xx*(xx-2)

case "easeinoutquad":
if (xx2<1)
return 1/2*xx2*xx2
return -1/2*((xx2-1)*(xx2-3)-1)

case "easeincubic":
return xx*xx*xx

case "easeoutcubic":
return ((xxm1)*xxm1*xxm1+1)

case "easeinoutcubic":
if (xx2<1)
return 1/2*xx2*xx2*xx2
return 1/2*((xx2-2)*(xx2-2)*(xx2-2)+2)

case "easeinquart":
return xx*xx*xx*xx

case "easeoutquart":
return -((xxm1)*xxm1*xxm1*xxm1-1)

case "easeinoutquart":
if (xx2<1)
return 1/2*xx2*xx2*xx2*xx2
return -1/2*((xx2-2)*(xx2-2)*(xx2-2)*(xx2-2)-2)

case "easeinquint":
return xx*xx*xx*xx*xx

case "easeoutquint":
return ((xxm1)*xxm1*xxm1*xxm1*xxm1+1)

case "easeinoutquint":
if (xx2<1)
return 1/2*xx2*xx2*xx2*xx2*xx2
return 1/2*((xx2-2)*(xx2-2)*(xx2-2)*(xx2-2)*(xx2-2)+2)

case "easeinsine":
return -cos(xx*(pi/2))+1

case "easeoutsine":
return sin(xx*(pi/2))

case "easeinoutsine":
return -1/2*(cos(pi*xx/1)-1)

case "easeinexpo":
return power(2,10*(xx-1))

case "easeoutexpo":
return -power(2,-10*xx)+1

case "easeinoutexpo":
if (xx2<1)
return 1/2*power(2,10*(xx2-1))
return 1/2*(-power(2,-10*(xx2-1))+2)

case "easeincirc":
return -(sqrt(1-xx*xx)-1)

case "easeoutcirc":
return sqrt(1-(xxm1)*xxm1)

case "easeinoutcirc":
if (xx2<1)
return -1/2*(sqrt(1-xx2*xx2)-1)
return 1/2*(sqrt(max(0,1-(xx2-2)*(xx2-2)))+1)

case "easeinelastic":
var p=0.3;
var s=p/(2*pi)*arcsin(1);
return -(power(2,10*(xx-1))*sin(((xx-1)*1-s)*(2*pi)/p))

case "easeoutelastic":
var p=0.3;
var s=p/(2*pi)*arcsin(1);
return power(2,-10*xx)*sin((xx*1-s)*(2*pi)/p)+1

case "easeinoutelastic":
var p=0.3*1.5;
var s = p/(2*pi)*arcsin(1);
if (xx2<1)
return -0.5*(power(2,10*(xx2-1))*sin(((xx2-1)*1-s)*(2*pi)/p))
return power(2,-10*(xx2-1))*sin(((xx2-1)*1-s)*(2*pi)/p)*0.5+1

case "easeinback":
var s=1.70158;
return xx*xx*((s+1)*xx-s)

case "easeoutback":
var s=1.70158;
return (xxm1*xxm1*((s+1)*xxm1+s)+1)

case "easeinoutback":
var s=1.70158;
if (xx2<1)
return 1/2*(xx2*xx2*(((s*(1.525))+1)*xx2-(s*(1.525))))
return 1/2*((xx2-2)*(xx2-2)*(((s*(1.525))+1)*(xx2-2)+(s*(1.525)))+2)

case "easeinbounce":
xx=1-xx
if (xx<(1/2.75))
return 1-(7.5625*xx*xx)
else if (xx<(2/2.75))
return 1-(7.5625*(xx-(1.5/2.75))*(xx-(1.5/2.75))+0.75)
else if (xx<(2.5/2.75))
return 1-(7.5625*(xx-(2.25/2.75))*(xx-(2.25/2.75))+0.9375)
else
return 1-(7.5625*(xx-(2.625/2.75))*(xx-(2.625/2.75))+0.984375)

case "easeoutbounce":
if (xx<(1/2.75))
return (7.5625*xx*xx)
else if (xx<(2/2.75))
return (7.5625*(xx-(1.5/2.75))*(xx-(1.5/2.75))+0.75)
else if (xx<(2.5/2.75))
return (7.5625*(xx-(2.25/2.75))*(xx-(2.25/2.75))+0.9375)
else
return (7.5625*(xx-(2.625/2.75))*(xx-(2.625/2.75))+0.984375)

case "easeinoutbounce":
var ret;
if (xx<1/2) {
xx*=2
xx=1-xx
if (xx<(1/2.75))
ret=(7.5625*xx*xx)
else if (xx < (2/2.75))
ret=(7.5625*(xx-(1.5/2.75))*(xx-(1.5/2.75))+0.75)
else if (xx < (2.5/2.75))
ret=(7.5625*(xx-(2.25/2.75))*(xx-(2.25/2.75))+0.9375)
else
ret=(7.5625*(xx-(2.625/2.75))*(xx-(2.625/2.75))+0.984375)
ret=1-ret
ret*=.5
} else {
xx=xx*2-1
if (xx<(1/2.75))
ret=(7.5625*xx*xx)
else if (xx < (2/2.75))
ret=(7.5625*(xx-(1.5/2.75))*(xx-(1.5/2.75))+0.75)
else if (xx < (2.5/2.75))
ret=(7.5625*(xx-(2.25/2.75))*(xx-(2.25/2.75))+0.9375)
else
ret=(7.5625*(xx-(2.625/2.75))*(xx-(2.625/2.75))+0.984375)
ret*=0.5
ret+=0.5
}
return ret
}

return xx

Thank you guys!
 

obscene

Member
When a case is true, all code after that point executes until it hits a break;

If there's no breaks ( hint ) all the stuff in the other cases below it gets executed.
 
Top