O'Reilly logo

HTML5 Game Development HOTSHOT by Makzan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a cross obstacle

We should be used to the static body by now. It is time to add more types of obstacles to the physics world.

In this task, we add a cross obstacle with motor spinning.

Engage thrusters

Let's execute the following steps to create a spinning cross in the world:

  1. First, we define a new method that creates a cross. It is a long method. A cross is constructed with two fixtures in one body and then a static body with a revolute joint to spin the cross:
    physics.createCross = function(obstacle) { var bodyDef = new b2BodyDef; var fixDef = new b2FixtureDef; // default fixture fixDef.density = 0.2; fixDef.friction = 0.5; fixDef.restitution = 0.2; bodyDef.type = b2Body.b2_dynamicBody; bodyDef.position.x = obstacle.position.x/pxPerMeter; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required