Time for action – connecting the box and two circles with a revolute joint

Carry out the following steps to create a car with the box and wheels:

  1. We are still working only on the logic part. Open our JavaScript logic file in a text editor.
  2. Create a function named createCarAt, which takes the coordinates as arguments. Then, move the body and the wheel creation code in this function. Afterwards, add the following highlighted joint creation code. At last, return the car body:
    function createCarAt(x, y) { var bodyDef = new b2BodyDef; var fixDef = new b2FixtureDef; // car body bodyDef.type = b2Body.b2_dynamicBody; bodyDef.position.x = 50/pxPerMeter; bodyDef.position.y = 210/pxPerMeter; fixDef.shape = new b2PolygonShape(); fixDef.density = 1.0; fixDef.friction ...

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.