I use parametric animations.
That is: normalize start and end situations (start = 0, end = 1) e.g. (millisecs() - startTime) / float(duration)
and then use the parameter to animate.
Then you can bias the parameter to ease-in or out the animation.
I hope this is what you mean.
example:
That is: normalize start and end situations (start = 0, end = 1) e.g. (millisecs() - startTime) / float(duration)
and then use the parameter to animate.
Then you can bias the parameter to ease-in or out the animation.
I hope this is what you mean.
example:
SuperStrict Graphics 800, 600, 0 'In this example I will use elapsed time as a parameter. 'The tween will take fDuration milliseconds Local fDuration# = 3000.0 '3000 millisecond Local iStart% = MilliSecs() Local fp# 'fp is the animation parameter Local fStartX# = 50 'start at 50,550 Local fStartY# = 550 Local fTargetX# = 750 'move to 750,50 Local fTargetY# = 50 While Not KeyHit(KEY_ESCAPE) 'press Esc to quit Cls 'use elapsed time to calculate parameter 'you can use whatever you like: number of frames, MouseX(), the hue of a color, the number of characters typed in a string, etc. fp = (MilliSecs() - iStart) / fDuration If fp >= 1 Then 'restart animation fp = 1 iStart = MilliSecs() End If 'select one of the bias functions ' fp = BiasIn(fp) 'accelerate ' fp = BiasOut(fp) 'decelerate ' fp = BiasBoth(fp) 'well.. accelerate and decelerate 'use parameter to find the 'inbetween' positions Local fx# = fp * (fTargetX - fStartX) + fStartX Local fy# = fp * (fTargetY - fStartY) + fStartY 'draw an oval at calculated x,y position DrawOval(fx-20, fy-20, 40, 40) Flip Wend End 'there are a lot of bias functions suitable. I've chosen these... Function BiasIn#(fp#) Return Sin((fp - 1) * 90) + 1 End Function Function BiasOut#(fp#) Return Sin(fp * 90) End Function Function BiasBoth#(fp#) Return (- Cos(fp * 180) + 1) / 2.0 End Function