Game Development Reference
In-Depth Information
Note
Sequences and Timelines are closely related terms, though not exactly
identical. Cocos2D uses the term
sequence
for any set of
CCAction
classes
wrapped in a
CCActionSequence
class that runs the actions it wraps in se-
quential order. For instance, when a node moves from A to B, then rotates 90
degrees, then moves to C, that's a sequence. A Timeline in SpriteBuilder can
then be considered a composite of multiple sequences because, for example,
you could also animate a node's opacity and scale while performing the move
and rotate actions. Generally speaking, a Timeline is one or more sequences
playing in parallel.
Every node instance has an
animationManager
property through which you can ac-
cess the
CCAnimationManager
and thus play back animations by name. For a quick
GameScene.m
.
Listing 5-1
.
Running an animation using CCAnimationManager
CCNode* sawNoAutoplay = [_physicsNode
getChildByName:@"sawNoAutoplay" recursively:YES];
[sawNoAutoplay.animationManager
runAnimationsForSequenceNamed:@"Default Timeline"];
The first line you should be familiar with. You obtain a reference to the node by name.
The animation manager is then instructed to run the sequence named
Default
Timeline
, which must be the exact name of the Timeline in SpriteBuilder, including
case. If you build and run this, you'll notice the non-autoplaying saw is now animating
again.
Note
It's important to note that each CCB file has its own
CCAnima-
tionManager
instance where only that specific CCB file's timelines are
stored. All Timeline animations edited in a CCB file are stored in the
CCAnim-
ationManager
of the CCB's root node, while each of the CCB's child node's
animationManager
instances forwards animation requests to the root
node's
animationManager
instance.
Therefore, in
Listing 5-1
it wouldn't work if you used, say, the
anima-
tionManager
of
self
(
GameScene.ccb
),
_physicsNode
or
Search WWH ::
Custom Search