Applying forces

Unlike impulses, forces must be applied over time to significantly move a body in the physical world. In this recipe, we see a simulation of our solar system.

Applying forces

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe.

How to do it...

Execute the following code:

@implementation Ch4_Forces -(CCLayer*) runRecipe { [super runRecipe]; //Set our gravity to 0 world->SetGravity(b2Vec2(0,0)); //Level background CCSprite *bg = [CCSprite spriteWithFile:@"solar_system_bg.png"]; bg.position = ccp(240,160); [gameNode addChild:bg z:0]; //Add Planets planets = [[[NSMutableDictionary alloc] init] autorelease]; ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.