Jarkko

To Box2D or not

Recommended Posts

Hello all

 

I've been making a small game, a clone of (Totem Destroyer) using Box2d. After testing the initial level  in couple of mobile phones, I'm not sure if it's worth the effort, as the framerate can drop around 7-8fps.

 

So I was wondering what is the general opinion about using Box2d in mobile browser, and if there are some tricks to optimize the performance.

Share this post


Link to post
Share on other sites

I would have to agree that it's best to avoid Box2D if you need to target mobile. There are other solutions out there though, but not a whole lot. Depending on how complex the physics is you could possibly try just coding it using math tutorials and the like?

Share this post


Link to post
Share on other sites

Thank you for all the replies. 

 

It seems that it is still too early for box2d to perform reliably on a mobile browser. 

Rich's suggestion to implement my own physics is something to consider. In fact, the engine I use (Impact) has rudimentary physics, but I would need to learn how to calculate angles of accelerating objects of different masses etc. 

For now, this particular project is put on the backburner.

Share this post


Link to post
Share on other sites

Over a month ago i'd vote on Chipmunk-JS as well. The engine was written in C, which means that it translates to JavaScript without all the problems that plague Box2D. The API stays near identical and from the tests i've ran, the performance is quite spectacular, both when it comes to speed and garbage generation.

 

These days however, there's only one physics engine i'd consider using, that is the one that's a part of the Turbulenz engine. You can use the physics engine separately without any problems and the APIs were designed to mirror Box2D's APIs, so the documentation should get you up to speed quickly. Turbulenz might be tricky to set up, but recently there's been a livestream organized to teach you everything to get the engine up and running.

 

If you're not sure if the work required to switch is worth it, check out the demos on the Turbulenz site. You can check how insanely well optimized the engine is if you use the developer tools. They used Typed Arrays extensively when developing the engine, with fall-backs of course, but that's about it for tricks AFAIK. If you're worried about Typed Array support, you probably shouldn't be.

Share this post


Link to post
Share on other sites

Rolnaaba, Dreta - Thanks for great tips! Maybe this game will start to go forward after all.

 

Getting to know Turbulenz has been on my todo list, however I was under the impression that it was primarily aimed at developing for 3d games for desktop. Still, it would be interesting to see how well the physics run on mobile browser. Also, it turns out that Chipmunk is available as a plugin for Impact engine, so I'll definitely check it out.

Share this post


Link to post
Share on other sites

I know I'm late to the conversation, but I've done a lot with box2d and wanted to chime in a little.    I like it.  The API is well documented, and on the desktop it works fairly well.   On mobile, performance is unbearable and isn't even an option, at least if you plan on running in a browser.

 

There are other downsides.  Many ports of box2d exist for the web and it can be confusing.   I use box2dweb, and I've found it to work well.   There are many ports that call themselves Box2dJS.  The most popular is a much older version of box2d and extremely buggy.  There is a newer one that looks alright, but it didn't work as a drop in replacement for box2dweb, and I haven't taken the time to look further.

 

A big problem is that most of the ports are made by scripts that converts the actionscript box2d port into javascript.  The code works pretty well, but the generated code is fairly awful and could perform a lot better.     There is an emscripten port, but that has its own issues and complications of going through their glue.    It also is much bigger in size.

 

I've found a few bugs in box2d web.  CCD doesn't behave properly, and joints in rare circumstances don't work right.  Overall though, I've found it to be really solid and perform well enough for the desktop.    Performance is better in Chrome than Firefox, and anyone with a far outdated browser or mobile browser is out of luck.

 

ChipmunkJS looks nice, and I've been waiting to see what more people produce with that before seriously considering making a switch.  There are two ports with that name, though I remember it seeming clear that one should be used over the other.    The code looked a lot better than box2d.   On the downside though, it doesn't have the community or widespread use of box2d.

 

I've chosen to stick with box2d for now, and one big reason is cocoonJS.    They have a native box2d build in their platform, so if you generate apps through cocoon you can leverage a native box2d and probably get good performance.  I haven't tested it yet, but it sounds potentially like a way of dealing with the performance issues on mobile.   If anyone has tried that, I'd be interested in hearing how well it works.

 

I haven't given Turbulenz's 2d physics a serious look yet.  It does seem interesting.   Good luck with your game.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.