Archive for the ‘motor 2’ Category

Initial impressions of Box2D and motor2

Sunday, May 17th, 2009

Over the last two weeks, I’ve been using the actionscript3 port of Box2D in a Flash platform game. It was the first time I’d done any proper work using Box2D and I wasn’t wholly enthused by the experience.

I’m sure it is a good physics engine for C++ developers but it has been ported very directly and I think could do with rewriting to fit with the actionscript language. It doesn’t feel like you’re learning an API, more like you’re venturing into another language, a task not helped by some lacklustre documentation and a need for good examples. No doubt, some optimisation could also improve matters.

Having said that, the engine is obviously powerful and provided many more features and physical simulations than I could possibly need in a simple game.

It was only after I’d got a fair way into the project that I had a look at another port of Box2D, this time from polygonal labs. I’ve been impressed with a lot of their articles, demos and the data structures class library, so I thought I’d investigate the motor2 physics engine a little further.

I have to admit I’ve only just scratched the surface of what both of these physics engines are capable of and my intentions are to carry on playing around and experimenting with both to see what I can get out of them.

In the meantime, here are some quick examples (with source code) to compare the two libraries:

Motor2 version (requires flash player 10):

Download the source code.

Box2D version:

Download the source code.

In both cases, I have made a very simple weighing scale from a revolute joint and a rigid box. I’ve then added another 98 boxes (49 either side) that fall on to the scale.

The motor2 engine has been updated to use the Vector functionality included with flash player 10 and makes use of the neat optimisation techniques you’d expect from Polygonal labs. Comparing the two on my PC (Dual Core 2.13GHz, 1Gb RAM with Windows XP and running the Firefox 3 browser), the motor 2 demo seems to run at a steady 45 to 50 fps where as the box2d version runs between 25 and 40 fps.

The motor 2 API has also had some minor tweaks to fit a little snugger with actionscript 3. I feel this makes it a little easier for a developer who works predominantly in Flash to start using the library.

While these are some initial impressions I have from looking at the two class libraries, I hope to put motor 2 to further use and will post some more demos here, in the near future.