Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 5. Animation > 5.2. Calculating Frame Rates

5.2. Calculating Frame Rates

Animations are a sequence of images, known as frames, that are displayed at a rate known as the frame rate. It’s often necessary to calculate an animation’s frame rate; for example, you may use an animation’s frame rate to implement time-based motion, as discussed in Section 5.6, “Time-Based Motion,” on p. 367, or you may simply want to ensure that your animation’s frame rate is sufficient for smooth animation.

The application shown in Figure 5.3 calculates the animation’s frame rate and displays it in the canvas.

image

Figure 5.3. Calculating frames per second

The code that calculates the frame rate is listed in Example 5.11, along with the application’s animation loop. Using a simple equation, the application calculates frames per second, given the elapsed time for the most recent animation frame.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial