HTML and CSS Reference
In-Depth Information
Your engine starts out with run() to test for SVG support, then moves on to setting up all
of the game's objects. The update() method is responsible for removing and/or chan-
ging game assets. You'll notice that a few of the init() items aren't in the update()
because they require a separate timer to fire.
Although it might seem like a good idea to use the animation timer requestAnima-
tionFrame here—as you did in the Canvas game in chapter 6 —don't. Clearing an an-
imation timer is difficult, programming in polyfills for intervals and/or timeouts is very
buggy, and some browsers don't like SVG coupled with timer-based animation. Until sup-
port improves, you're better off using setTimeout() and setInterval() unless
you're working with a Canvas application.
Step 2: Integrate screen transitions
In order to make use of the Welcome and Game Over screens you created earlier, you'll
need the code in the following listing to add a few more methods for deleting SVG ele-
ments and mouse-click monitoring.
Search WWH ::

Custom Search