Jarkko Posted June 7, 2013 Share Posted June 7, 2013 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. Quote Link to comment Share on other sites More sharing options...
P.Uri.Tanner Posted June 7, 2013 Share Posted June 7, 2013 Barely usable on the average desktop. Not usable on mobile.Maybe after asm.js or similar projects have increased code performance. Might be a while. Jarkko 1 Quote Link to comment Share on other sites More sharing options...
tyson Posted June 7, 2013 Share Posted June 7, 2013 I think Box2D is OK on mobile, i did a test with just basic fills on canvas it it was about 30fps on iOS and 20 on Android. Probably depends on how many bodies and sprites you have. http://www.tysonross.com/2013/05/31/box2d-game-experiment-working-title-star-chaser/ --Tys Jarkko and rsadwick 2 Quote Link to comment Share on other sites More sharing options...
P.Uri.Tanner Posted June 8, 2013 Share Posted June 8, 2013 Box2D Benchmarks on different VMs: http://j15r.com/blog/2013/04/25/Box2d_Revisited Jarkko 1 Quote Link to comment Share on other sites More sharing options...
rich Posted June 8, 2013 Share Posted June 8, 2013 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? ad29b and Jarkko 2 Quote Link to comment Share on other sites More sharing options...
Jarkko Posted June 8, 2013 Author Share Posted June 8, 2013 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. ad29b and Jarkko 2 Quote Link to comment Share on other sites More sharing options...
xerver Posted June 8, 2013 Share Posted June 8, 2013 Have you tried Chipmunk-js at all? It is tiny compared to box2dweb but still is feature packed. Jarkko 1 Quote Link to comment Share on other sites More sharing options...
dreta Posted June 9, 2013 Share Posted June 9, 2013 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. P.Uri.Tanner, Jarkko and rob 3 Quote Link to comment Share on other sites More sharing options...
Jarkko Posted June 9, 2013 Author Share Posted June 9, 2013 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. Quote Link to comment Share on other sites More sharing options...
dhaber Posted June 21, 2013 Share Posted June 21, 2013 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. ad29b 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.