Tween

public class
loom2d.animation.Tween

Description

A Tween animates numeric properties of objects. It uses different transition functions to give the animations various styles.

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)'
Loom2D.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:
loom2d.animation.Juggler
loom2d.animation.Transitions

API overview

Constructor

Tween ( target: Object , time: Number , transition: Object = linear )
Creates a tween with a target, duration (in seconds) and a transition function

Attributes

Public attributes

currentTime: Number read-only

The time that has passed since the tween was created

delay: Number

The delay before the tween is started

isComplete: Boolean read-only

Indicates if the tween is finished

nextTween: Tween

Another tween that will be started (i.e

onComplete: Function

A function that will be called when the tween is complete

onCompleteArgs: Vector.<Object>

The arguments that will be passed to the 'onComplete' function

onRepeat: Function

A function that will be called each time the tween finishes one repetition (except the last, which will trigger 'onComplete')

onRepeatArgs: Vector.<Object>

The arguments that will be passed to the 'onRepeat' function

onStart: Function

A function that will be called when the tween starts (after a possible delay)

onStartArgs: Vector.<Object>

The arguments that will be passed to the 'onStart' function

onUpdate: Function

A function that will be called each time the tween is advanced

onUpdateArgs: Vector.<Object>

The arguments that will be passed to the 'onUpdate' function

progress: Number read-only

The current progress between 0 and 1, as calculated by the transition function

remainingTime: Number

The remaining time before the tween finishes

repeatCount: Number

The number of times the tween will be executed

repeatDelay: Number

The amount of time to wait between repeat cycles, in seconds

reverse: Boolean

Indicates if the tween should be reversed when it is repeating

roundToInt: Boolean

Indicates if the numeric values should be cast to Integers

target: Object read-only

The target object that is animated

totalTime: Number read-only

The total time the tween will take per repetition (in seconds)

transition: String

The transition method used for the animation

transitionFunc: Function

The actual transition function used for the animation

Functions

Public functions

advanceTime ( time: Number ): Void

Advance the time by a number of seconds

animate ( property: String , endValue: Number ): Void

Animates the property of the target to a certain value

fadeTo ( alpha: Number ): Void

Animates the 'alpha' property of an object to a certain target value

getEndValue ( property: String ): Number

The end value a certain property is animated to

moveTo ( x: Number , y: Number ): Void

Animates the 'x' and 'y' properties of an object simultaneously

reset ( target: Object , time: Number , transition: Object = linear ): Tween

Resets the tween to its default values

resetSoft (): Void

Resets a minimal number of the tween values so that it can be started again

scaleTo ( factor: Number ): Void

Animates the 'scaleX' and 'scaleY' properties of an object simultaneously

Constructor

Tween ( target: Object , time: Number , transition: Object = linear )

Creates a tween with a target, duration (in seconds) and a transition function. @param target the object that you want to animate @param time the duration of the Tween @param transition 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.

Attributes

currentTime: Number

read-only

The time that has passed since the tween was created.

delay: Number
The default value is 0

The delay before the tween is started.

isComplete: Boolean

read-only

Indicates if the tween is finished.

nextTween: Tween

Another tween that will be started (i.e. added to the same juggler) as soon as this tween is completed.

onComplete: Function

A function that will be called when the tween is complete.

onCompleteArgs: Vector.<Object>

The arguments that will be passed to the 'onComplete' function.

onRepeat: Function

A function that will be called each time the tween finishes one repetition (except the last, which will trigger 'onComplete').

onRepeatArgs: Vector.<Object>

The arguments that will be passed to the 'onRepeat' function.

onStart: Function

A function that will be called when the tween starts (after a possible delay).

onStartArgs: Vector.<Object>

The arguments that will be passed to the 'onStart' function.

onUpdate: Function

A function that will be called each time the tween is advanced.

onUpdateArgs: Vector.<Object>

The arguments that will be passed to the 'onUpdate' function.

progress: Number

read-only

The current progress between 0 and 1, as calculated by the transition function.

remainingTime: Number

The remaining time before the tween finishes.

repeatCount: Number
The default value is 1

The number of times the tween will be executed. Set to '0' to tween indefinitely.

repeatDelay: Number
The default value is 0

The amount of time to wait between repeat cycles, in seconds.

reverse: Boolean
The default value is false

Indicates if the tween should be reversed when it is repeating. If enabled, every second repetition will be reversed.

roundToInt: Boolean
The default value is false

Indicates if the numeric values should be cast to Integers.

target: Object

read-only

The target object that is animated.

totalTime: Number

read-only

The total time the tween will take per repetition (in seconds).

transition: String

The transition method used for the animation. See also:
loom2d.animation.Transitions

transitionFunc: Function

The actual transition function used for the animation.

Functions

addEventListener ( type: String , listener: Function ): Void
Inherited from EventDispatcher

Registers an event listener at a certain object.

Parameters

type: String
listener: Function


advanceTime ( time: Number ): Void

Advance the time by a number of seconds.

Parameters

time: Number


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.

Parameters

property: String
endValue: Number


dispatchEvent ( event: Event ): Void
Inherited from EventDispatcher

Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.

Parameters

event: Event


dispatchEventWith ( type: String , bubbles: Boolean = false , data: Object = null ): Void
Inherited from EventDispatcher

Dispatches an event with the given parameters to all objects that have registered listeners for the given type. The method uses an internal pool of event objects to avoid allocations.

Parameters

type: String
bubbles: Boolean = false
data: Object = null


fadeTo ( alpha: Number ): Void

Animates the 'alpha' property of an object to a certain target value.

Parameters

alpha: Number


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


getFullTypeName (): String
Inherited from Object

native

Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.


Returns

String fully qualified type name of the Object.

getType (): Type
Inherited from Object

native

Gets the Type that describes the Object.


Returns

Type The Type that describes the object.

getTypeName (): String
Inherited from Object

native

Gets the type name of the Object.


Returns

String type name of the Object.

hasEventListener ( type: String ): Boolean
Inherited from EventDispatcher

Returns if there are listeners registered for a certain event type.

Parameters

type: String


moveTo ( x: Number , y: Number ): Void

Animates the 'x' and 'y' properties of an object simultaneously.

Parameters

x: Number
y: Number


removeEventListener ( type: String , listener: Function ): Void
Inherited from EventDispatcher

Removes an event listener from the object.

Parameters

type: String
listener: Function


removeEventListeners ( type: String = null ): Void
Inherited from EventDispatcher

Removes all event listeners with a certain type, or all of them if type is null. Be careful when removing all event listeners: you never know who else was listening.

Parameters

type: String = null


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 = linear


resetSoft (): Void

Resets a minimal number of the tween values so that it can be started again. Useful for manual restarts of a Tween where you don't have access to the original values.



scaleTo ( factor: Number ): Void

Animates the 'scaleX' and 'scaleY' properties of an object simultaneously.

Parameters

factor: Number


toString (): String
Inherited from Object

native

Returns a String that describes the Object. This can be overriden to provide extra details when printing objects using trace().


Returns

String String that described the Object.

: