Package | starling.animation |
Class | public class Tween |
Inheritance | Tween EventDispatcher Object |
Implements | IAnimatable |
The primary use of this class is to do standard animations like movement, fading,
rotation, etc. But there are no limits on what to animate; as long as the property you want
to animate is numeric (int, uint, Number
), the tween can handle it. For a list
of available Transition types, look at the "Transitions" class.
Here is an example of a tween that moves an object to the right, rotates it, and fades it out:
var tween:Tween = new Tween(object, 2.0, Transitions.EASE_IN_OUT); tween.animate("x", object.x + 50); tween.animate("rotation", deg2rad(45)); tween.fadeTo(0); // equivalent to 'animate("alpha", 0)' Starling.juggler.add(tween);
Note that the object is added to a juggler at the end of this sample. That's because a tween will only be executed if its "advanceTime" method is executed regularly - the juggler will do that for you, and will remove the tween when it is finished.
See also
Property | Defined By | ||
---|---|---|---|
currentTime : Number [read-only] The time that has passed since the tween was created (in seconds). | Tween | ||
delay : Number The delay before the tween is started (in seconds). | Tween | ||
isComplete : Boolean [read-only] Indicates if the tween is finished. | Tween | ||
nextTween : Tween Another tween that will be started (i.e. | Tween | ||
onComplete : Function A function that will be called when the tween is complete. | Tween | ||
onCompleteArgs : Array The arguments that will be passed to the 'onComplete' function. | Tween | ||
onRepeat : Function A function that will be called each time the tween finishes one repetition
(except the last, which will trigger 'onComplete'). | Tween | ||
onRepeatArgs : Array The arguments that will be passed to the 'onRepeat' function. | Tween | ||
onStart : Function A function that will be called when the tween starts (after a possible delay). | Tween | ||
onStartArgs : Array The arguments that will be passed to the 'onStart' function. | Tween | ||
onUpdate : Function A function that will be called each time the tween is advanced. | Tween | ||
onUpdateArgs : Array The arguments that will be passed to the 'onUpdate' function. | Tween | ||
progress : Number [read-only] The current progress between 0 and 1, as calculated by the transition function. | Tween | ||
repeatCount : int The number of times the tween will be executed. | Tween | ||
repeatDelay : Number The amount of time to wait between repeat cycles (in seconds). | Tween | ||
reverse : Boolean Indicates if the tween should be reversed when it is repeating. | Tween | ||
roundToInt : Boolean Indicates if the numeric values should be cast to Integers. | Tween | ||
target : Object [read-only] The target object that is animated. | Tween | ||
totalTime : Number [read-only] The total time the tween will take per repetition (in seconds). | Tween | ||
transition : String The transition method used for the animation. | Tween | ||
transitionFunc : Function The actual transition function used for the animation. | Tween |
Method | Defined By | ||
---|---|---|---|
Tween(target:Object, time:Number, transition:Object = linear) Creates a tween with a target, duration (in seconds) and a transition function. | Tween | ||
addEventListener(type:String, listener:Function):void Registers an event listener at a certain object. | EventDispatcher | ||
advanceTime(time:Number):void Advance the time by a number of seconds. | Tween | ||
animate(property:String, endValue:Number):void Animates the property of the target to a certain value. | Tween | ||
animatesProperty(property:String):Boolean Indicates if a property with the given name is being animated by this tween. | Tween | ||
dispatchEvent(event:Event):void Dispatches an event to all objects that have registered listeners for its type. | EventDispatcher | ||
dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void Dispatches an event with the given parameters to all objects that have registered
listeners for the given type. | EventDispatcher | ||
fadeTo(alpha:Number):void Animates the 'alpha' property of an object to a certain target value. | Tween | ||
getEndValue(property:String):Number The end value a certain property is animated to. | Tween | ||
hasEventListener(type:String, listener:Function = null):Boolean If called with one argument, figures out if there are any listeners registered for
the given event type. | EventDispatcher | ||
moveTo(x:Number, y:Number):void Animates the 'x' and 'y' properties of an object simultaneously. | Tween | ||
removeEventListener(type:String, listener:Function):void Removes an event listener from the object. | EventDispatcher | ||
removeEventListeners(type:String = null):void Removes all event listeners with a certain type, or all of them if type is null. | EventDispatcher | ||
Resets the tween to its default values. | Tween | ||
rotateTo(angle:Number, type:String = rad):void Animates the 'rotation' property of an object to a certain target value, using the
smallest possible arc. | Tween | ||
scaleTo(factor:Number):void Animates the 'scaleX' and 'scaleY' properties of an object simultaneously. | Tween |
currentTime | property |
currentTime:Number
[read-only] The time that has passed since the tween was created (in seconds).
public function get currentTime():Number
delay | property |
delay:Number
The delay before the tween is started (in seconds).
The default value is 0
.
public function get delay():Number
public function set delay(value:Number):void
isComplete | property |
isComplete:Boolean
[read-only] Indicates if the tween is finished.
public function get isComplete():Boolean
nextTween | property |
nextTween:Tween
Another tween that will be started (i.e. added to the same juggler) as soon as this tween is completed.
public function get nextTween():Tween
public function set nextTween(value:Tween):void
onComplete | property |
onComplete:Function
A function that will be called when the tween is complete.
public function get onComplete():Function
public function set onComplete(value:Function):void
onCompleteArgs | property |
onCompleteArgs:Array
The arguments that will be passed to the 'onComplete' function.
public function get onCompleteArgs():Array
public function set onCompleteArgs(value:Array):void
onRepeat | property |
onRepeat:Function
A function that will be called each time the tween finishes one repetition (except the last, which will trigger 'onComplete').
public function get onRepeat():Function
public function set onRepeat(value:Function):void
onRepeatArgs | property |
onRepeatArgs:Array
The arguments that will be passed to the 'onRepeat' function.
public function get onRepeatArgs():Array
public function set onRepeatArgs(value:Array):void
onStart | property |
onStart:Function
A function that will be called when the tween starts (after a possible delay).
public function get onStart():Function
public function set onStart(value:Function):void
onStartArgs | property |
onStartArgs:Array
The arguments that will be passed to the 'onStart' function.
public function get onStartArgs():Array
public function set onStartArgs(value:Array):void
onUpdate | property |
onUpdate:Function
A function that will be called each time the tween is advanced.
public function get onUpdate():Function
public function set onUpdate(value:Function):void
onUpdateArgs | property |
onUpdateArgs:Array
The arguments that will be passed to the 'onUpdate' function.
public function get onUpdateArgs():Array
public function set onUpdateArgs(value:Array):void
progress | property |
progress:Number
[read-only] The current progress between 0 and 1, as calculated by the transition function.
public function get progress():Number
repeatCount | property |
repeatCount:int
The number of times the tween will be executed. Set to '0' to tween indefinitely.
The default value is 1
.
public function get repeatCount():int
public function set repeatCount(value:int):void
repeatDelay | property |
repeatDelay:Number
The amount of time to wait between repeat cycles (in seconds).
The default value is 0
.
public function get repeatDelay():Number
public function set repeatDelay(value:Number):void
reverse | property |
reverse:Boolean
Indicates if the tween should be reversed when it is repeating. If enabled, every second repetition will be reversed.
The default value is false
.
public function get reverse():Boolean
public function set reverse(value:Boolean):void
roundToInt | property |
roundToInt:Boolean
Indicates if the numeric values should be cast to Integers.
The default value is false
.
public function get roundToInt():Boolean
public function set roundToInt(value:Boolean):void
target | property |
target:Object
[read-only] The target object that is animated.
public function get target():Object
totalTime | property |
totalTime:Number
[read-only] The total time the tween will take per repetition (in seconds).
public function get totalTime():Number
transition | property |
transition:String
The transition method used for the animation.
public function get transition():String
public function set transition(value:String):void
See also
transitionFunc | property |
transitionFunc:Function
The actual transition function used for the animation.
public function get transitionFunc():Function
public function set transitionFunc(value:Function):void
Tween | () | Constructor |
public function Tween(target:Object, time:Number, transition:Object = linear)
Creates a tween with a target, duration (in seconds) and a transition function.
Parameterstarget:Object — the object that you want to animate
| |
time:Number — the duration of the Tween (in seconds)
| |
transition:Object (default = linear ) — can be either a String (e.g. one of the constants defined in the
Transitions class) or a function. Look up the 'Transitions' class for a
documentation about the required function signature. |
advanceTime | () | method |
public function advanceTime(time:Number):void
Advance the time by a number of seconds.
Parameters
time:Number — in seconds. |
animate | () | method |
public function animate(property:String, endValue:Number):void
Animates the property of the target to a certain value. You can call this method multiple times on one tween.
Some property types are handled in a special way:
color
or Color
,
it will be treated as an unsigned integer with a color value
(e.g. 0xff0000
for red). Each color channel will be animated
individually.#rgb
to the name.#rad
, the property is treated as an angle in radians,
making sure it always uses the shortest possible arc for the rotation.#deg
does the same for angles in degrees.Parameters
property:String | |
endValue:Number |
animatesProperty | () | method |
public function animatesProperty(property:String):Boolean
Indicates if a property with the given name is being animated by this tween.
Parameters
property:String |
Boolean |
fadeTo | () | method |
public function fadeTo(alpha:Number):void
Animates the 'alpha' property of an object to a certain target value.
Parameters
alpha:Number |
getEndValue | () | method |
public function getEndValue(property:String):Number
The end value a certain property is animated to. Throws an ArgumentError if the property is not being animated.
Parameters
property:String |
Number |
moveTo | () | method |
public function moveTo(x:Number, y:Number):void
Animates the 'x' and 'y' properties of an object simultaneously.
Parameters
x:Number | |
y:Number |
reset | () | method |
public function reset(target:Object, time:Number, transition:Object = linear):Tween
Resets the tween to its default values. Useful for pooling tweens.
Parameters
target:Object | |
time:Number | |
transition:Object (default = linear )
|
Tween |
rotateTo | () | method |
public function rotateTo(angle:Number, type:String = rad):void
Animates the 'rotation' property of an object to a certain target value, using the smallest possible arc. 'type' may be either 'rad' or 'deg', depending on the unit of measurement.
Parameters
angle:Number | |
type:String (default = rad )
|
scaleTo | () | method |
public function scaleTo(factor:Number):void
Animates the 'scaleX' and 'scaleY' properties of an object simultaneously.
Parameters
factor:Number |