Game Development Reference
In-Depth Information
Chapter
5
Timelines & Triggers
One of SpriteBuilder's major features is its ability to create Timeline animations using key-
frames. It can even animate static physics bodies through keyframes while providing prop-
er physics collisions, a feature that is unheard of in other 2D game engines.
This chapter explains how to create Timeline animations with SpriteBuilder and how to
play such animations using CCBAnimationManager . At the end, you'll have rotating
physics gear and saw objects that can push the player forward.
You'll also create a reusable trigger node that you can place in the level with a correspond-
ing Trigger class. This allows you to run code when the player enters the trigger
area—for instance, playing a Timeline animation on target nodes.
What Are Timelines and Keyframes?
So far you've known the Timeline as a view in SpriteBuilder (see Figure 5-1 ) and as the
area where the hierarchy of nodes in a CCB is presented. You mainly used it to change the
draw order of nodes and to rename them. But the Timeline can also animate properties of
nodes using keyframes.
A keyframe animation simply records the values of properties of a node at a given key-
frame. Say you have three keyframes and, for example, the rotation property is being anim-
ated. As the Timeline animation moves from one keyframe to the next, the node's rotation
property is continuously updated. The difference between the most recent keyframe's rota-
tion value and the next keyframe's rotation value, as well as the easing mode, determines
how the rotation value changes over time. The entire animation is called a Timeline in
SpriteBuilder.
Keyframe animations enable you to create smooth animations with relatively few key-
frames because the in-between values are interpolated. Furthermore, the interpolation can
be changed from a linear progression to an equation that computes the values between two
Search WWH ::




Custom Search