Looking through the top selling IOS apps (well, the games section), it seems like having realistic physics is the place to be. (Angry Birds of course, but also others like Cover Orange, Cut The Rope, and the new number one app Tiny Wings).
Tiny Wings (excellent by the way) credits Box2D on one of it’s screens – this got me thinking how easy it would be to get something up and running that uses the Box2D library.
There’s a lot of stuff out there regarding Box2D on IOS, but most of it is related to cocos2d, and that’s not really my thing. Fortunately for me, I found an excellent blog post on Cocoanetics which walks you through how to quickly get Box2D working in a simple app.
My code is based largely on their excellent work (and of course the equally impressive Box2D library itself) – the changes I’ve made are purely to get something working using Open GL.
The code here generates a universal app (ipad or iphone/ipod touch). All the blocks are generated at random (size, colour, linear and angular velocity). Touching the screen restarts the process (or waiting for the blocks to all stop moving…).
Change the MAX_RECTS define in the ViewController.h file to change how many blocks are generated – size and colour info is done in Rectangle.m. Here’s the project:
Side note – the project is called nibfree as I was originally trying to get a universal opengl app working with no nib file (done!).
I’m not sure why, but it’s quite mesmerising watching how the blocks fall.
Big thanks to the Cocoanetics guys for their original blog.
As usual, any feedback at all is welcomed.






