Book Image

HTML5 Game Development by Example: Beginner's Guide

By : Seng Hin Mak
Book Image

HTML5 Game Development by Example: Beginner's Guide

By: Seng Hin Mak

Overview of this book

Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Building a Physics Car Game with Box2D and Canvas
Index

Introducing the HTML5 canvas element


W3C community states that the canvas element and the drawing functions are as follows:

A resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, or other visual images on the fly.

The canvas element contains context for drawing and the actual graphics and shapes are drawn by the JavaScript drawing API. There is one key difference between using canvas and the usual HTML DOM elements. Canvas is an immediate mode while DOM is a retained mode. We describe the DOM tree with elements and attributes, and the browser renders and tracks the objects for us. In Canvas, we have to manage all the attributes and rendering ourselves. The browser doesn't keep the information of what we draw. It only keeps the drawn pixel data.