Juggler
Description
The Juggler takes objects that implement IAnimatable (like Tweens) and executes them.
A juggler is a simple object. It does no more than saving a list of objects implementing "IAnimatable" and advancing their time if it is told to do so (by calling its own "advanceTime"-method). When an animation is completed, it throws it away.
There is a default juggler available at the Starling class:
var juggler:Juggler = Loom2D.juggler;
You can create juggler objects yourself, just as well. That way, you can group your game into logical components that handle their animations independently. All you have to do is call the "advanceTime" method on your custom juggler once per frame.
Another handy feature of the juggler is the "delayCall"-method. Use it to execute a function at a later time. Different to conventional approaches, the method will only be called when the juggler is advanced, giving you perfect control over the call.
juggler.delayCall(object.removeFromParent, 1.0);
juggler.delayCall(object.addChild, 2.0, theChild);
juggler.delayCall(function():void { doSomethingFunny(); }, 3.0);
See also:
loom2d.animation.Tween
loom2d.animation.DelayedCall
API overview
Constructor
Juggler
()
Create an empty juggler
Functions
Public functions
| add ( object: IAnimatable ): Void |
Adds an object to the juggler |
| advanceTime ( time: Number ): Void |
Advances all objects by a certain time (in seconds) |
| contains ( object: IAnimatable ): Boolean |
Determines if an object has been added to the juggler |
| containsTweens ( target: Object ): Boolean |
Figures out if the juggler contains one or more tweens with a certain target |
| delayCall ( call: Function , delay: Number , args: Vector.<Object> ): DelayedCall |
Delays the execution of a function until a certain time has passed |
| purge (): Void |
Removes all objects at once |
| remove ( object: IAnimatable ): Void |
Removes an object from the juggler |
| removeTweens ( target: Object ): Void |
Removes all tweens with a certain target |
| tween ( target: Object , time: Number , properties: Dictionary.<String, Object> ): Tween |
Utilizes a tween to animate the target object over a certain time |
Constructor
Juggler ()
Create an empty juggler.
Attributes
Functions
advanceTime ( time: Number ): Void
Advances all objects by a certain time (in seconds).
Parameters
| time: Number |
contains ( object: IAnimatable ): Boolean
Determines if an object has been added to the juggler.
Parameters
| object: IAnimatable |
containsTweens ( target: Object ): Boolean
Figures out if the juggler contains one or more tweens with a certain target.
Parameters
| target: Object |
delayCall ( call: Function , delay: Number , args: Vector.<Object> ): DelayedCall
Delays the execution of a function until a certain time has passed. Creates an object of type 'DelayedCall' internally and returns it. Remove that object from the juggler to cancel the function call.
Parameters
| call: Function | |
| delay: Number | |
| args: Vector.<Object> |
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. |
remove ( object: IAnimatable ): Void
Removes an object from the juggler.
Parameters
| object: IAnimatable |
removeTweens ( target: Object ): Void
Removes all tweens with a certain target.
Parameters
| target: Object |
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. |
tween ( target: Object , time: Number , properties: Dictionary.<String, Object> ): Tween
Utilizes a tween to animate the target object over a certain time. Internally, this method uses a tween instance (taken from an object pool) that is added to the juggler right away. This method provides a convenient alternative for creating and adding a tween manually.
Fill 'properties' with key-value pairs that describe both the tween and the animation target. Here is an example:
juggler.tween(object, 2.0, {
transition: Transitions.EASE_IN_OUT,
delay: 20, // -> tween.delay = 20
x: 50 // -> tween.animate("x", 50)
});
Parameters
| target: Object | |
| time: Number | |
| properties: Dictionary.<String, Object> |