Game Development Reference
In-Depth Information
local theText = display.newText("Hello, hope you are enjoying your journey with Lua so far",0,440)
theText.x = theText.contentWidth
theText.trans = transition.to(
theText,{time=8000, x=-theText.contentWidth})
--
local ball = display.newCircle ( 160, 480, 50 )
ball:setFillColor(255,255,0)
ball.alpha = 0.5
ball:scale(0.5,0.5)
--
transition.to (ball, {time = 2000, y = 80, transition = easing.outExpo , onComplete=function()
transition.cancel(theText.trans)
end} )
In this code, transition = easing.outExpo causes the ball to slow down and then speed up as it
moves toward the top of the screen.
You can also add other interesting effects by simply writing your own easing function. Such a
function is declared as follows:
easing.function( t , tMax , start , delta )
In this declaration, t is the time since the start of the transition, tMax is the overall length of the
transition time, start is the initial value, and delta is the change in the value at the end of the
transition. The final value should always be start + delta .
Here's an example of easeOutBounce , with the result illustrated in Figure 8-16 .
function easeOutBounce(t,b,c,d)
t,d,b,c= t,b,c,d;
t=t/d;
if (t<(1/2.75)) then
ret=c*(7.5625*t*t)+b
elseif (t<(2/2.75)) then
t=t-(1.5/2.75)
ret=c*(7.5625*(t*t)+.75)+b
elseif (t<(2.5/2.75)) then
t=t-2.25/2.75;
ret=c*(7.5625*t*t+.9375)+b
else
t=t-2.625/2.75;
ret=c*(7.5625*t*t+.984375)+b
end
return ret;
end
This code is taken from the LHTween library on GitHub, authored by logHound.
Search WWH ::




Custom Search