January 27 2009

Box2d: Bringing 2D physics to screens everywhere

What I´m going to write about here is physics in Flash, AS3. And since I like keeping it old school it is 2D physics. Lonely Duck has just finished a small game that you will soon be able to catch in a banner near you. The physics are handled by Box2D, a physics engine ported from C++. When doing physics in AS3 you have a number of different engines to choose from. Even though you are planning to use physics with lets say Papervision3D or any other flash 3d environment you can still use a 2D physics engine, if you keep your objects in one plane with interactions along 2 axis. This means that you won´t be able to support 3d interaction (e.g movement in x,y,z) but in some cases this isn´t really needed.

Anyway, I first gave APE (Actionscript Physics Engine) a go. It was really easy getting started with and the setup of the 2d world and the objects I was going to use worked as expected. After a while (about 50% done) I however found that it was lacking some fundamental stuff that I really wanted. Things like collision detection, a way to avoid tunneling issues and an environment with a more complex collection of different joints and springs. The answer was as I already mentioned Box2D, and even thought the fact that is was a port from C++ first scared me a little (different ways of organizing code, positions and values are on a meter basis, which means that one meter is equal to 30 pixels) now feels great to have started with. Not only because it could be used in many upcoming AS3 projects, it is also possible to use Box2D when developing applications for the iPhone.

There are a number of popular apps out there that uses Box2D for the physics.

These have all been done through porting box2d from C++ to Obj C. Which means writing their own renderers and touch listeners for interaction. Good times however, now there is a released port of the Box2d testbed with working interaction from the touch sensors and the accelerometer. Check out this post explaining things a little bit better here.

Take care!

Greg Findon on 01/28/09

Was just reading your post about Box2D, we have literally just launched the site (www.milkmatters.co.uk) which relies heavily on box2d as its engine. At some point when I get round to it I will be writing an in depth look at how it was built, and the problems we faced.

In the meantime, good luck with your investigations, it’s easily the best physics option out there, even if it’s documentation etc. is a little confusing!

GRACEly on 02/07/10

It’s not so simply to bring a pretty good written essay, essentially if you are booked. I give advice you to set buy essay and to be free from disbelief that your work will be done by essay writing services

Leave a comment

Name (required)

Mail (required)

Website

Text