Difference between revisions of "GTween.new"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2010-2011<br/> '''Class:''' GTween<br/> === Description === Constructs a new GTween instance. <syntaxhighlight lang="lua"> GTween...")
 
 
(4 intermediate revisions by the same user not shown)
Line 12: Line 12:
  
 
''props'' is also a table and accepts the following keys (the ''props'' table is optional):
 
''props'' is also a table and accepts the following keys (the ''props'' table is optional):
 +
* '''useFrames''' (bool, default = false), counts tween in frames instead of seconds (0 based)
 
* '''delay''' (number, default = 0), a delay before starting the tween
 
* '''delay''' (number, default = 0), a delay before starting the tween
 
* '''ease''' (''easing'', default = linear), sets the ease property of the new instance
 
* '''ease''' (''easing'', default = linear), sets the ease property of the new instance
 
* '''repeatCount''' (number, default = 1), number of times the tween should repeat
 
* '''repeatCount''' (number, default = 1), number of times the tween should repeat
* '''dispatchEvents''' (''bool'', default = false), allows dispatching of '''"change"''' and '''"complete"''' events
+
* '''reflect''' (bool, default = false), reflects the tween (checks '''repeatCount''' > 1 and odd or even)
* '''swapValues''' (''bool'', default = false), causes :swapValues() to be called after the values specified in the ''values'' parameter are set
+
* '''dispatchEvents''' (''bool'', default = false), allows dispatching of '''"change"''', '''"complete"''' and the special '''"init"''' events
 +
* '''swapValues''' (''bool'', default = false), starts the tween from the end after the values specified in the ''values'' parameter are set
  
 
=== Parameters ===
 
=== Parameters ===

Latest revision as of 07:33, 8 December 2025

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):

  • useFrames (bool, default = false), counts tween in frames instead of seconds (0 based)
  • 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", "complete" and the special "init" 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)