HTML and CSS Reference
In-Depth Information
You'll notice that you've wrapped your Game.setup() code in window.onload . It
makes the browser wait to fire setup until index.html has completely loaded. Running Can-
vas code too soon could result in crashing if essential assets (such as libraries) haven't
loaded yet.
Step 2: Create HTML5-optimized animation
Before you start drawing, you'll need to set up animation. But there's a catch: Canvas relies
on JavaScript timers because animation isn't built in. To create animation you must use a
timer to constantly draw shapes. Normally you'd use JavaScript's setInterval() , but
that won't provide users with an optimal experience. setInterval() is designed for
running equations or carrying out DOM manipulation, not processor-intensive animation
loops.
Search WWH ::




Custom Search