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. It calls the
createWheel
function which we will write to create a circular shaped body:// create two wheels in the world createWheel(carGame.world, 25, 230); createWheel(carGame.world, 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. Put the following function in our JavaScript logic file:function createWheel(world, x, y) { // wheel circle definition var ballSd = new b2CircleDef(); ballSd.density = 1.0; ballSd.radius = 10; ballSd.restitution = 0.1; ballSd.friction = 4.3; // body definition var ballBd = new b2BodyDef(); ballBd.AddShape(ballSd); ballBd.position.Set(x,y); return world.CreateBody(ballBd); }
4. We...