Animating on the Canvas

The player ship we just created has two frames (static and thrust), but we can display only a single frame at a time. Our game will need to switch out the frame of animation based on the state of the player ship, and it will need to run on a timer so that this animation can occur. Let’s take a quick look at the code necessary to create our game timer.

Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.