Interactivity with Box2D

So far, we have simply placed objects in a defined Box2D world and let them move on their own. While that type of application is great for teaching or instruction, creating an interactive world with Box2D is a path to creating exciting games and simulations on the Canvas.

For this example, we will create a game where you shoot balls at a pile of boxes and knock them over. However, before we get to that example, we will start with a simpler iteration where we display some boxes and model them falling and rotating. (See Figure 5-28.)

Boxes falling and rotating

Figure 5-28. Boxes falling and rotating

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.