GTween
From GiderosMobile
Supported platforms:
Available since: Gideros 2010-2011
Description
GTween is a light-weight instance oriented tween engine. This means that you instantiate tweens for specific purposes, and then reuse, update or discard them.
This is different than centralized tween engines where you "register" tweens with a global object. This provides a more familiar and useful interface for object oriented programmers.
GTween boasts a number of advanced features:
- frame and time based durations/positions which can be set per tween
- simple sequenced tweens using .nextTween
- pause and resume individual tweens or all tweens
- jump directly to the end or beginning of a tween with :toEnd() or :toBeginning()
- jump to any arbitrary point in the tween with :setPosition()
- complete, init, and change callbacks
- smart garbage collector interactions (prevents collection while active, allows collection if target is collected)
- easy to set up in a single line of code
- can repeat or reflect a tween a specified number of times
- deterministic, so setting a position on a tween will (almost) always result in predictable results
GTween (Gideros Tween) is more a Class than a plugin per se. Since you may find several projects/code sample using it, I figured I could put it in the Plugins section of Gideros Wiki
To use the GTween library, add the following file to your project:
- Gtween.lua tip: right click and "Save Link As"
Note: GTween uses the Easing plugin so make sure to add it in your Plugins
Example
require "easing"
application:setBackgroundColor(0x626262)
local x = 8*32
local y = 8*32
local pixel = Pixel.new(math.random(0xffffff), 1, 32, 32)
pixel:setAnchorPoint(0.5, 0.5)
pixel:setPosition(x, y)
stage:addChild(pixel)
--function GTween:init(target, duration, values, props)
local tween = GTween.new(
pixel, 1,
{
x=x,
y=y-4*32,
alpha=1.7,
scaleY=2.5,
},
{
delay=4,
ease=easing.outBack,
repeatCount=1,
dispatchEvents=true,
}
)
tween.nextTween = GTween.new(
pixel, 0.7,
{
y=y,
alpha=1,
scaleY=1,
},
{
ease=easing.outBounce,
repeatCount=1,
}
)
tween:addEventListener("complete", function()
-- tween:toEnd() -- toBeginning(), toEnd()
-- tween:setPosition(0.75)
print("tweened!")
end)
See also