photonstorm/phaser — pull request #545 by georgiee (2014-03-12 07:55:28+00:00)
Title: Box2D integration

Hello,
here a first version of a box2d integration in phaser. It was a breeze to integrate it :) Thanks rich for that plugable physics architecture. I think it's no good idea to merge this a day before the planned release of 1.2.
I just wanted to show you a first version and create a place where I can update my progress.

**It's based on that version:**
box2d-html5.googlecode.com
This is based on Box2D, 2.3 (r278) (That's the first 2.3 release, Nov 3, 2013)

Isaac Burns, the author of that repository did a great job porting all box2d c files by hand.
And he keeps on doing this. The latest commit is from Feb 15, 2014. (see https://code.google.com/p/box2d-html5/source/list)

It's still plenty to do but it's running, there are polygons/rectangles & circles available through the Phaser box2d body, there are collision groups/masks & categories accessible and I have integrate some debug drawing, of course :)

**The biggest problem for now:**
Minification. I can't run the grunt tasks, I get a 'stack level too deep' when the file `src/physics/box2d/box2d-html5.js` is processed. This is the file containing the box2d port. It's compiled with google closure, so I guess that causes the error? I had no time to debug this, as it's really secondary for now.
It's running okay on mobile, but I guess there should be some optimisations regarding velocity and position iterations. They are set to 8/10, default is 8/3.

**The most exciting things to do will be:**
You can use all of the features from box2d with the current implementation but it would be nice to have some convenience methods to create joints more easily and use some of the more advanced features like Buoyancy (pseudo fluid through antigravity), Breakable, RayCast, Motors, special Bullet Bodies, Sensors and and and :)

Here alle the cool box2d features in the testbed of the port.
https://box2d-html5.googlecode.com/svn/demo/index.html

For the future it would be good to create some kind of physics benchmark to compare the different systems in context of the Phaser System. There are no good js physics benchmarks but this would be pretty useful to make predictions for the mobile ecosystem.

Here's a preview (see my 'important' note regarding performance)
http://georgiee.github.io/phaser+box2d/
![screenshot](https://f.cloud.github.com/assets/1701755/2394395/bf8b26da-a9b1-11e3-81ca-e2e51949852b.png)

**Important:**
My fan is really going up since I merged the latest changes from Phaser itself minutes ago. I can't see anything related to box2d in my profiling. The newly merged changes include the separated coreUpdate. Maybe this causes the performance drop ? See my screenshot attached.
![screen shot 2014-03-12 at 08 41 26](https://f.cloud.github.com/assets/1701755/2394714/4b57ae7e-a9ba-11e3-8035-61b77e3439bf.png)