The magic of compound objects with Box2D – HTML5 version powered by Phaser

Back in 2008 I blogged about the magic of compound objects with Box2D to create complex shapes, and eventually built a game upon this concept, called MazeRoll.

Now it’s time to do the same thing with Phaser, building a maze in a single body.

The maze is built with the same script used in Pure JavaScript perfect tile maze generation – with a bit of magic thanks to Phaser, have a look at it:

Try to drag the mouse, you will see it’s a single body made with more fixtures.

Everything runs around the creation of a body with no fixtures – think about it as an empty body – with rectangular fixtures added to it at runtime with addRectangle method.

addRectangle(width, height, offsetX, offsetY, rotation)

Adds a Rectangle fixture to a Body. You can control the offset from the center of the body and the rotation. It will use the World friction, restitution and density by default.

This is the source code.

And this is how you can create compound objects with Box2D and Phaser. Next time, I will port my MazeRoll game in HTML5, meanwhile download the source code.

  • Gabriel

    It’s very laggy, even for my i7 computer. Why is it?