Search code examples
game-physicsphaser-framework

Make a sprite behave like a rigid body in Phaser.io


I am trying to create a little simulation with Phaser.IO. The idea is implement simulate something like a box where you can let balls (or some other polygon) fall.

The polygon must behave like a rigid body when dropped (IE. collide with other balls and the box wall)

I have implemented (sort of) that using Physics.js: http://jsbin.com/poxehenu/1

Now, I want to implement the same with Phaser.IO, but could not find a way to make the balls collide with other balls like they collide with the world bounds.

I came to this: http://jsbin.com/pozoy/4

Is that possible with Phaser.IO?


Solution

  • You need to use the P2 Physics system that comes with Phaser. Have a look at the Phaser Examples and scroll down to the P2 section specifically. There should be plenty of examples there to get you started, then you can use the API docs to fill in the blanks.