The GTween library by Grant Skinner ported from ActionScript to Lua and Ansca’s Corona SDK by Josh Tynjala.
For those familiar with Corona, usage is very similar to transition.to, but gtween offers a variety of useful features that go beyond Corona’s built-in transitions. If you’ve used GTween in ActionScript, then gtween.lua should look very familiar.
local gtween = require("gtween")
bc.
local redSquare = display.newRect( 0, 0, 100, 100 )
redSquare:setFillColor( 255, 0, 0 )
redSquare.x = 60
redSquare.y = 60
local blueSquare = display.newRect( 0, 0, 100, 100 )
blueSquare:setFillColor( 0, 0, 255 )
blueSquare.x = 170
blueSquare.y = 60
blueSquare.alpha = 0
local function redSquareMove_onChange( tween )
blueSquare.x = redSquare.x + 150
blueSquare.y = redSquare.y
blueSquare.alpha = 1 – redSquare.alpha
end
-[[-
gtween.new
Parameters:
1. target
2. duration in seconds
3. table of end values
4. table of gtween properties (separate from tweened values to avoid collisions)
]]
gtween.new(redSquare, 1.5,
{
x = 260,
y = 260,
alpha = 0
},
{
transitionEase = easing.outQuad, —standard Corona ease
repeatCount = math.huge, —repeat forever!
reflect = true, —yoyo
onChange = redSquareMove_onChange —called after every update
})
Corona uses a non-standard signature for its built-in easing functions, but the gtween.lua port has been modified to support them. Use the transitionEase
property (see the example above) to tell gtween.lua to use one of the easing functions designed for use with Corona’s transitions. Use ease
(same as ActionScript) to use a standard easing function.
The following features from the original ActionScript GTween are not included in this port. They may be added in the future.
- GTweenTimeline
- Plugins
- Easing functions are not included, but see see the Easing section above for more information.