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.
Hey great test!
I wrote a game (LineGolfer – http://www.candystand.com/play.do?id=18253) using APE previously, and while good I really had to hack into it to get what I wanted out of it. Plus it seems to be stagnant.
So I on this project i’m going to start, i thought i’d mess around with the new kids on the block and do some test.
I was going to spend sunday afternoon doing something similar, here you’ve already done it!
Mario – Thanks for the comment, I’m glad you found the post helpful. I’m going to write a few more posts on motor2 over the next few weeks. I’ll probably focus on using it for platform games to begin with. LineGolfer is cool. I really was bad at it but good stuff.
hello,
i also spent some time comparing both Motor2 and Box2D.
Here are my thoughts:
Box2D seems more powerful in terms of features but originally not written in AS3 … so that using it and digging in it’s code was not intuitive at all.
Motor2 may be less powerful in terms of features (less constraints, …) but originally written in AS3.
As i needed to custom the engine to fit my needs, i decided to start with Motor2 … up to now i don’t regret my choice.
I just hope that Motor2 is not a dead project and that there will be further releases.