Graphics Reference
In-Depth Information
Monitoring Keyframe Destinations
To further understand how to apply the key times formula, go to the companion website
at informit.com/coreframeworks and open the demo project called Keyframe Steps. You
notice we have added timers that fire at various stages of the animation to show which
point we have reached in the animation. In the Keyframe Steps example code, we animate
a dot around the window in the path of a five-pointed star, as shown in Figure 4-3. As the
animation reaches each point, we draw the segment of the path from the previous point
to the next; this is done with timers. First, however, we had to determine how many
keyframes we needed and then determined how many timers we would need.
FIGURE 4-3
Keyframe Steps Demo Application
In the sample code, we have specified 10 seconds as the animation's duration. To deter-
mine how much time the animation would spend between each destination point, we
applied the formula based on the duration and the number of keyframes. Including the
animation's starting and ending points, there are a total of 6 keyframes. We then apply
the animation timing formula as follows:
Duration / (keyframes -1) = time per keyframe
10 / (6-1) = 2.0 seconds per keyframe
Notice in Listing 4-4 that NSTimer is used to schedule a selector to run every 2 seconds
during the animation. This causes the path to be updated and redrawn to show the star
path as each destination is reached.
Search WWH ::




Custom Search