Here is some example code based off my tutorial on how to implement orbital / radial gravity, but in reverse. This example pushes objects away instead of pulling inward. It makes for a nice explosion effect. Much work would need to be done to make it realistic, but you get the general idea of how to blow things up. You need to have Cocos2D and Box2D installed. Box2D comes packaged with the latest version if Cocos2D.

Download Source Code for this tutorial:
Bomb Demo Box2d & Cocos2d Example Source Code – 799k
Random Posts:
- iOS Core Location GPS Tutorial pt.1
- Hunting trip pictures
- iAd Profit, the truth
- Source Code to iStrobe
- iStrobe FREE for a week
If you found this useful, shoot me a small donation or at the very least leave a comment, every bit of encouragement helps keep me motivated to update with more content on a regular basis!
Tags: bomb, box2d, C++, cocos2d, code, explosion, iPhone, Objective-C, orbital gravity, radial gravity, source code, tutorial, Xcode
You can leave a response, or trackback from your own site.
Thanks for this… I modified it a little to make a more realistic explosion. I added a ‘bomblife’ variable that turns off the bomb gravity after a set period of ticks. This makes the falling blocks fall without being pushed away from the circles.
Like this:
Funny you posted this. I was just thinking yesterday how I wanted to implement a timer to turn off the force. Thank you! I will be updating this in the next week or so to implement something like this.