SPJuggler Class Reference
Inherits from | NSObject |
Conforms to | SPAnimatable |
Declared in | SPJuggler.h |
Overview
The SPJuggler takes objects that implement SPAnimatable (e.g. SPTween
s) and executes them.
A juggler is a simple object. It does no more than saving a list of objects implementing
SPAnimatable
and advancing their time if it is told to do so (by calling its own advanceTime:
method). Furthermore, an object can request to be removed from the juggler by dispatching an
SPEventTypeRemoveFromJuggler
event.
There is a default juggler that you can access from anywhere with the following code:
SPJuggler *juggler = Sparrow.juggler;
You can, however, create juggler objects yourself, too. That way, you can group your game into logical components that handle their animations independently.
A cool feature of the juggler is to delay method calls. Say you want to remove an object from its parent 2 seconds from now. Call:
[[juggler delayInvocationAtTarget:object byTime:2.0] removeFromParent];
This line of code will execute the following method 2 seconds in the future:
[object removeFromParent];
Alternatively, you can use the block-based verson of the method:
[juggler delayInvocationByTime:2.0 block:^{ [object removeFromParent]; };
Tasks
Initialization
-
+ juggler
Factory method.
Methods
-
– addObject:
Adds an object to the juggler.
-
– removeObject:
Removes an object from the juggler.
-
– removeAllObjects
Removes all objects at once.
-
– removeObjectsWithTarget:
Removes all objects with a
target
property referencing a certain object (e.g. tweens or delayed invocations). -
– containsObject:
Determines if an object has been added to the juggler.
-
– delayInvocationAtTarget:byTime:
Delays the execution of a certain method. Returns a proxy object on which to call the method instead. Execution will be delayed until
time
has passed. -
– delayInvocationByTime:block:
Delays the execution of a block by a certain time in seconds.
Properties
-
elapsedTime
The total life time of the juggler.
property -
speed
The speed factor adjusts how fast a juggler’s animatables run. For example, a speed factor of 2.0 means the juggler runs twice as fast.
property
Properties
elapsedTime
The total life time of the juggler.
@property (nonatomic, readonly) double elapsedTime
Discussion
The total life time of the juggler.
Declared In
SPJuggler.h
speed
The speed factor adjusts how fast a juggler’s animatables run. For example, a speed factor of 2.0 means the juggler runs twice as fast.
@property (nonatomic, assign) float speed
Discussion
The speed factor adjusts how fast a juggler’s animatables run. For example, a speed factor of 2.0 means the juggler runs twice as fast.
Declared In
SPJuggler.h
Instance Methods
addObject:
Adds an object to the juggler.
- (void)addObject:(id<SPAnimatable>)object
Discussion
Adds an object to the juggler.
Declared In
SPJuggler.h
containsObject:
Determines if an object has been added to the juggler.
- (BOOL)containsObject:(id<SPAnimatable>)object
Discussion
Determines if an object has been added to the juggler.
Declared In
SPJuggler.h
delayInvocationAtTarget:byTime:
Delays the execution of a certain method. Returns a proxy object on which to call the method
instead. Execution will be delayed until time
has passed.
- (id)delayInvocationAtTarget:(id)target byTime:(double)time
Discussion
Delays the execution of a certain method. Returns a proxy object on which to call the method
instead. Execution will be delayed until time
has passed.
Declared In
SPJuggler.h
delayInvocationByTime:block:
Delays the execution of a block by a certain time in seconds.
- (id)delayInvocationByTime:(double)time block:(SPCallbackBlock)block
Discussion
Delays the execution of a block by a certain time in seconds.
Declared In
SPJuggler.h
removeAllObjects
Removes all objects at once.
- (void)removeAllObjects
Discussion
Removes all objects at once.
Declared In
SPJuggler.h
removeObject:
Removes an object from the juggler.
- (void)removeObject:(id<SPAnimatable>)object
Discussion
Removes an object from the juggler.
Declared In
SPJuggler.h
removeObjectsWithTarget:
Removes all objects with a target
property referencing a certain object (e.g. tweens or
delayed invocations).
- (void)removeObjectsWithTarget:(id)object
Discussion
Removes all objects with a target
property referencing a certain object (e.g. tweens or
delayed invocations).
Declared In
SPJuggler.h