Ive been playing with the excellent cocos2d iPhone game programming library, with the intention of making some sort of, no-doubt rubbish, game. So far i’ve just been experimenting and I’ve decided to, albeit briefly, write up my learnings as I go.

The simulation running (better in action!)
This article/project covers:
- Cocos2d
- Chipmunk collision detection
- Orbital/gravity physics
- Particle emitters
Cocos2d: for game mechanics
The cocos2d framework is quite simply amazing. Ricardo Quesada & co have done a excellent job of getting this together. Ive only rubbed off a miniscule amount of its power I suspect. The framework lets you put together a game, easily. It manages game logic (like menus, scenes, Â and transitions), game mechanics (sprites, textures, animation, etc) and all manner of other things. This example simply uses the cocos2d framework to help glue everything together. A future post (and research) will(/may!) cover more of cocos2d in further detail.
Chipmunk: for physics collision detection and mechanics
One of the key concepts of the game I have in mind involves a satellite orbiting some planets. The cocos2d library comes with the Chipmunk physics library, so what better place to start. I spent some time playing with this library. It pretty clever and lets you very quickly setup a virtual reality physics environment (in 2d at least). Whilst Chipmunk  provides all manner of  useful stuff, one thing it doesnt really deal with, as far as I can tell, is simulate a ’space’ environment. So I had to look elsewhere for that…
So although not using Chipmunk to model my physics, I do use it to model collision detection (its very good at that) and also I use it for controlling the movement of my shapes around the simulation – it deals with rotation, mass, bounciness, all sorts of goodness.
Maths: for physics!
As I couldn’t make Chipmunk do what I wanted I had to find another solution. It turns out the math for orbital physics is either a) very simple or b) very complicated. I found a simple model which essentially says that the further an object is away from a given object the less effect it has on its velocity vector (direction and speed). So i simply take my object in question – a satellite – and on each step of the simulation work out the effect that all the other bodies have on its velocity vector. I then plug this into the Chipmunk simulation and all is good. You can find all this math goodness in the assessGravity method.
Particle Emitters
Particle emitters are fun and look cool for little work. I use a particle emitter to simulate a fiery tail of my satellite. I dont know why this satellite is on fire, it just is. The emitter used here is based on the one thats in the cocos2d emitter examples. Ive just pulled it out into its own thang. Now I know how to do that I should be able to plug it into other projects…
Try it Yourself
This article is brief, but the code is commented. Download it and give it a go. I’m sure there are better ways to do everything, but this is my first go so be kind! (improvements and recommendations welcome!)
X-Code files here: SimpleOrbit (ive removed the build dir so significantly smaller now!)