O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required