GTween.new
Available since: Gideros 2010-2011
Class: GTween
Description
Constructs a new GTween instance.
GTween.new(target,duration,values,props)
values is a table and works as key, value pairs. The key is the function to tween and the value is the end value of the tween. You can use any function that transforms a Sprite (e.g. x, y, scale, rotation, scale, alpha, ...) as the key. For example, you can pass scaleX as the key and 2 as the value, this will tween the scale on the x axis. To tween to x=100, y=100, you would pass {x=100, y=100} as the values object.
props is also a table and accepts the following keys (the props table is optional):
- delay (number, default = 0), a delay before starting the tween
- ease (easing, default = linear), sets the ease property of the new instance
- repeatCount (number, default = 1), number of times the tween should repeat
- reflect (bool, default = false), reflects the tween (checks repeatCount > 1 and odd or even)
- dispatchEvents (bool, default = false), allows dispatching of "change" and "complete" events
- swapValues (bool, default = false), starts the tween from the end after the values specified in the values parameter are set
Parameters
target: (Sprite) the object whose properties will be tweened
duration: (number) the length of the tween in frames or seconds depending on the timingMode
values: (table) a table containing end property values
props: (table) a table containing properties to set on this tween, optional
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:addEventListener("complete", function()
-- tween:toEnd() -- toBeginning(), toEnd()
-- tween:setPosition(0.75)
print("tweened!")
end)