GTween class allows to animate Gideros objects like Sprite, and everything inherited from Sprites.

So what can you tween:

  • x position
  • y position
  • alpha value
  • scaleX ratio
  • scaleY ratio
  • rotation degrees

Additional options:

  • delay - delay tweening for specified amount of second or frames (default: 0)
  • ease - easing from easing.lua (default: linear)
  • repeatCount - how many times to repeat animation (default: 1)
  • reflect - reverse animation back (default: false)
  • autoPlay - automatically start animation (default: true)
  • swapValues -  use provided values as starting ones and existing values as target values(default: false)
  • timeScale - ratio of speed of animation (default: 1)
  • useFrames - bool, use frames instead of seconds for tween duration
  • dispatchEvents - dispatch tween event (default: false)
    • possible events:
      • init - initialization 
      • change - each time values are changed 
      • complete - when animation completes

Here is an example of using GTween class:

--define what to animate
local animate = {}
animate.y = 100
animate.x = 100
animate.alpha = 0.5
animate.scaleX = 0.5
animate.scaleY = 0.5
animate.rotation = math.random(0, 360)

--define GTween properties
local properties = {}
properties.delay = 0
properties.ease = easing.inElastic
properties.dispatchEvents = true

--animate them
--- First argument: sprite to animate
--- Second argument: duration of animation in seconds or frames
--- Third argument: properties to animate
--- Fourth argument: GTween properties
local tween = GTween.new(sprite, 10, animate, properties)

--adding event on animaiton complete
tween:addEventListener("complete", function()
	stage:removeChild(sprite)
	sprite = nil
end)

GTween class also provides some methods to manage tween animation:

  • GTween:isPaused() -  check is tween is paused
  • GTween:setPaused(value) - true or false to pause/unpause
  • GTween:getPosition() - position of animation (time span) from -delay to repeatCount*duration
  • GTween:setPosition(value) - jump to specified position of animation
  • GTween:getDelay() - get delay value
  • GTween:setDelay(value) -  set delay in seconds or frames
  • GTween:setValue(name, value) -  change animation value, example setValue("alpha", 1)
  • GTween:getValue(name) -  get end value for specified property
  • GTween:deleteValue(name) - delete value, so it won't be animated
  • GTween:setValues(values) - set values to animate
  • GTween:resetValues(values) - resets previous animation values and sets new ones
  • GTween:getValues() - returns table with animation values
  • GTween:getInitValue(name) - returns initial value of specified property
  • GTween:swapValues() - make existing animation values as target values and start animation from provided animation values
  • GTween:toBeginning() - go to beggining of animation and pause it
  • GTween:toEnd() - go to the end of animation

Bonus content: You can use easing for GTween animations using easing.lua and here are the easing options:

  • easing.inBack
  • easing.outBack
  • easing.inOutBack
  • easing.inBounce
  • easing.outBounce
  • easing.inOutBounce
  • easing.inCircular
  • easing.outCircular
  • easing.inOutCircular
  • easing.inCubic
  • easing.outCubic
  • easing.inOutCubic
  • easing.inElastic
  • easing.outElastic
  • easing.inOutElastic
  • easing.inExponential
  • easing.outExponential
  • easing.inOutExponential
  • easing.linear
  • easing.inQuadratic
  • easing.outQuadratic
  • easing.inOutQuadratic
  • easing.inQuartic
  • easing.outQuartic
  • easing.inOutQuartic
  • easing.inQuintic
  • easing.outQuintic
  • easing.inOutQuintic
  • easing.inSine
  • easing.outSine
  • easing.inOutSine