Difference between revisions of "GTween"

From GiderosMobile
 
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 +
<!-- GIDEROSOBJ:GTween -->
 
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform pc.png]][[File:Platform mac.png]][[File:Platform winrt.png]][[File:Platform win32.png]][[File:Platform linux.png]]<br/>
 
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform pc.png]][[File:Platform mac.png]][[File:Platform winrt.png]][[File:Platform win32.png]][[File:Platform linux.png]]<br/>
 
'''Available since:''' Gideros 2010-2011<br/>
 
'''Available since:''' Gideros 2010-2011<br/>
Line 20: Line 21:
 
* deterministic, so setting a position on a tween will (almost) always result in predictable results
 
* 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'''
+
  '''GTween (Gideros Tween) is more a Class than a plugin per se'''
  
 
To use the GTween library, add the following file to your project:
 
To use the GTween library, add the following file to your project:
 
* '''[[Media:gtween.lua|Gtween.lua]]''' '''tip: right click and "Save Link As"'''
 
* '''[[Media:gtween.lua|Gtween.lua]]''' '''tip: right click and "Save Link As"'''
  
  '''Note''': GTween uses the '''Easing''' plugin so make sure to add it in your Plugins
+
  '''Note''': GTween uses the '''[[Easing]]''' plugin so make sure to add it to your project Plugins
  
 
=== Example ===
 
=== Example ===
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
require "easing"
+
--[[
 +
Demonstration of GTween class
  
application:setBackgroundColor(0x626262)
+
This code is MIT licensed, see http://www.opensource.org/licenses/mit-license.php
 +
(C) 2010 - 2011 Gideros Mobile
 +
]]
  
local x = 8*32
+
local sprite = Bitmap.new(Texture.new("box.png"))
local y = 8*32
+
stage:addChild(sprite)
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)
+
GTween.new(sprite, 2, {x = 240}, {delay = 0.2, ease = easing.outBounce, repeatCount = 2, reflect = true})
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)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=== See also ===
 
=== See also ===
'''[[Easing]]'''
+
'''[[Ftf_libs#GFX]]'''<br/>
 +
 
 +
{|-
 +
| style="width: 50%; vertical-align:top;"|
 +
 
 +
=== Methods ===
 +
[[GTween.new]] ''creates a new GTween object''<br/><!--GIDEROSMTD:GTween.new(target,duration,values,props) creates a new GTween object-->
 +
[[GTween.nextTween]] ''sequenced tweens''<br/><!--GIDEROSMTD:GTween.nextTween(target,duration,values,props) sequenced tweens-->
 +
[[GTween.stopAll]] ''stops all tweens''<br/><!--GIDEROSMTD:GTween.stopAll() stops all tweens-->
 +
 
 +
[[GTween:deleteValue]] ''removes an end value from the tween''<br/><!--GIDEROSMTD:GTween:deleteValue(name) removes an end value from the tween-->
 +
[[GTween:getDelay]] ''gets the length of the delay in frames or seconds''<br/><!--GIDEROSMTD:GTween:getDelay() gets the length of the delay in frames or seconds-->
 +
[[GTween:getInitValue]] ''returns the initial value for the specified property''<br/><!--GIDEROSMTD:GTween:getInitValue(name) returns the initial value for the specified property-->
 +
[[GTween:getPosition]] ''gets the position of the tween in frames or seconds''<br/><!--GIDEROSMTD:GTween:getPosition() gets the position of the tween in frames or seconds-->
 +
[[GTween:getValue]] ''returns the end value for the specified property if one exists''<br/><!--GIDEROSMTD:GTween:getValue(name) returns the end value for the specified property if one exists-->
 +
[[GTween:getValues]] ''returns the table of all end properties and their values''<br/><!--GIDEROSMTD:GTween:getValues() returns the table of all end properties and their values-->
 +
[[GTween:init2]] ''reads all of the initial values from target and calls the "init" callback''<br/><!--GIDEROSMTD:GTween:init2() reads all of the initial values from target and calls the "init" callback-->
 +
[[GTween:isPaused]] ''returns the pause state of the tween''<br/><!--GIDEROSMTD:GTween:isPaused() returns the pause state of the tween-->
 +
[[GTween:resetValues]] ''clears all previous end values before setting the new ones''<br/><!--GIDEROSMTD:GTween:resetValues(values) clears all previous end values before setting the new ones-->
 +
[[GTween:setDelay]] ''sets the length of the delay in frames or seconds''<br/><!--GIDEROSMTD:GTween:setDelay(value) sets the length of the delay in frames or seconds-->
 +
[[GTween:setPaused]] ''plays or pauses a tween''<br/><!--GIDEROSMTD:GTween:setPaused(bool) plays or pauses a tween-->
 +
[[GTween:setPosition]] ''sets the position of the tween in frames or seconds''<br/><!--GIDEROSMTD:GTween:setPosition(value) sets the position of the tween in frames or seconds-->
 +
[[GTween:setValue]] ''sets the numeric end value for a property''<br/><!--GIDEROSMTD:GTween:setValue(name, value) sets the numeric end value for a property-->
 +
[[GTween:setValues]] ''shorthand method for making multiple setProperty calls''<br/><!--GIDEROSMTD:GTween:setValues(values) shorthand method for making multiple setProperty calls-->
 +
[[GTween:swapValues]] ''swaps the init and end values for the tween''<br/><!--GIDEROSMTD:GTween:swapValues() swaps the init and end values for the tween-->
 +
[[GTween:toBeginning]] ''jumps the tween to its beginning and pauses it''<br/><!--GIDEROSMTD:GTween:toBeginning() jumps the tween to its beginning and pauses it-->
 +
[[GTween:toEnd]] ''jumps the tween to its end and pauses it''<br/><!--GIDEROSMTD:GTween:toEnd() jumps the tween to its end and pauses it-->
 +
 
 +
| style="width: 50%; vertical-align:top;"|
 +
 
 +
=== Events ===
 +
'''"change"'''<br/>
 +
'''"complete"'''<br/>
 +
'''"init"'''<br/>
 +
 
 +
=== Constants ===
 +
|}
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 07:32, 8 December 2025

Supported platforms: Platform android.pngPlatform ios.pngPlatform pc.pngPlatform mac.pngPlatform winrt.pngPlatform win32.pngPlatform linux.png
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

To use the GTween library, add the following file to your project:

Note: GTween uses the Easing plugin so make sure to add it to your project Plugins

Example

--[[
Demonstration of GTween class

This code is MIT licensed, see http://www.opensource.org/licenses/mit-license.php
(C) 2010 - 2011 Gideros Mobile 
]]

local sprite = Bitmap.new(Texture.new("box.png"))
stage:addChild(sprite)

GTween.new(sprite, 2, {x = 240}, {delay = 0.2, ease = easing.outBounce, repeatCount = 2, reflect = true})

See also

Ftf_libs#GFX

Methods

GTween.new creates a new GTween object
GTween.nextTween sequenced tweens
GTween.stopAll stops all tweens

GTween:deleteValue removes an end value from the tween
GTween:getDelay gets the length of the delay in frames or seconds
GTween:getInitValue returns the initial value for the specified property
GTween:getPosition gets the position of the tween in frames or seconds
GTween:getValue returns the end value for the specified property if one exists
GTween:getValues returns the table of all end properties and their values
GTween:init2 reads all of the initial values from target and calls the "init" callback
GTween:isPaused returns the pause state of the tween
GTween:resetValues clears all previous end values before setting the new ones
GTween:setDelay sets the length of the delay in frames or seconds
GTween:setPaused plays or pauses a tween
GTween:setPosition sets the position of the tween in frames or seconds
GTween:setValue sets the numeric end value for a property
GTween:setValues shorthand method for making multiple setProperty calls
GTween:swapValues swaps the init and end values for the tween
GTween:toBeginning jumps the tween to its beginning and pauses it
GTween:toEnd jumps the tween to its end and pauses it

Events

"change"
"complete"
"init"

Constants