5. Creating Games with the Canvas Tag

The Canvas (that is, the canvas tag) is what many think about when HTML5 is mentioned. Instead of creating a bunch of div elements with contained images with CSS to simulate movement and game play, you can use canvas to provide a surface to draw objects on the screen. Neither method is easier or harder, but each has different considerations. The Canvas has some built-in translation, rotation, scaling, and clipping, whereas with divs you have to handle transformations yourself. However, one advantage that games using div and CSS have over the Canvas is that older browsers, such as Internet Explorer 6, are supported. Hopefully, as more browsers become HTML5 compliant, this will become less of an issue.

Getting ...

Get Learning HTML5 Game Programming: Build Online Games with Canvas, SVG, and WebGL 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.