Time for action – putting two circles in the world

We will add two circles to the world by carrying out the following steps:

  1. Open the html5games.box2dcargame.js JavaScript file to add the wheel bodies.
  2. Add the following code after the box creation code. This calls the createWheel function which we will write to create a circular shaped body:
    // create two wheels in the world
    createWheel(25, 230);
    createWheel(75, 230);
  3. Now let's work on the createWheel function. We design this function to create a circle-shaped body in the given world at the given x and y coordinates in the world. To do this, put the following function in our JavaScript logic file:
    function createWheel(x, y) { var bodyDef = new b2BodyDef; var fixDef = new b2FixtureDef; bodyDef.type ...

Get HTML5 Game Development by Example : Beginner's Guide - Second 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.