Whilst porting my game framework to Haxe, the collision detection system started acting weird, I spent a little bit of time trying to fix it but realised it was going to require more time. This, however, was a good thing, rather than getting stuck straight in and trying to fix it, I thought it would be a great opportunity to learn Nape; a relatively new physics engine built in Haxe (utilising the speed benefits Haxe offers) but compiled for ActionScript. And if all goes well, I would replace my current collision methods with Nape.
I haven’t really used Box2D or any other physics engine but I once built a Peggle-esc demo game using Box2D and there were two things that bugged me about it, firstly its real-world unit system, everything was measured in metres which meant all my object positions and sizes had to be adjusted with a multiplier, not really a big issue but just isn’t nice to have to do. Second, the verbose code, just to make a box appear on the screen requires something like 9 lines of code. I guess I also have a third issue which is I just want more, more boxes, more collisions, more destruction. Perhaps this is not entirely down to Box2D’s.
Now comparing Nape to Box2D, firstly it works in pixels which is just so much nicer and easier to work with. Second, the api is clean and simple and much faster to implement. And for my third issue, Nape is faster so I can have more boxes, more collisions and more deconstruction.
But as with everything I do, I like to shop around first and before I integrated Nape into my framework, I wanted to make sure I had picked the best engine. Because I am working with Haxe I wanted to compare Nape with a Haxe port of Box2D, I also wanted to test out Physaxe, a Haxe based physics engine written by the very talented creator of Haxe, Nicolas Cannasse, it has to be good! There are several ports of Box2D for Haxe but I chose Joshua Granicks port because of his great work on NME and because he is always willing to help out a Haxe/NME n00b(me).
- Flash Test., Nape outperformed the other two by quite some margin. Box2D and Physaxe performed comparably.
- Android Test. All three performed comparably here. The optimizations Nape uses when targeting Flash cannot be used here, which probably explains why it does not outperform the other two.
So where does this leave me, well back at square one. I will have to go back to my collision detection and finish porting it to Haxe. There’s so much development going on right now that I’m sure if I were to re-create these tests in a couple of months I would get totally different results.
Click the images to open the test.
Box2D Haxe Flash