Free Trial

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

Share this Page URL
Help

Chapter 5. Animation > 5.12. Conclusion - Pg. 391

5.12 Conclusion 391 most animations, especially games, it's essential that the animations proceed at a steady rate, even if the application slows down. As you saw in this chapter, it's easy to implement time-based motion that's frame rate independent, at least for simple cases of motion. Keep in mind that the browser automatically implements double buffering for you in Canvas elements. Because the browser double buffers the display, you don't need to implement double buffering yourself, but it's often useful to use one or more offscreen buffers, especially for complicated backgrounds. Remember that all other things being equal, you will generally get better performance by copying complicated backgrounds from offscreen buffers rather than redrawing those backgrounds for every animation frame. Shadows, along with gradients, whether they are of the CSS Canvas variety, can be performance killers, especially on mobile devices. Be sure to test your applica- tions both with and without shadows and gradients if your application is running slowly. Finally, you should try to avoid allocating memory during your animations so the browser does not run the garbage collector, or at least that it collects garbage