O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

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

Adding physics objects

For the physics engine to do any sort of work, we need to add physics objects to the scene. So, let's go ahead and add a physics object to the scene.

Getting started

All the work to get our physics objects to start simulating is already done in the previous section; so it is just a matter of adding the objects to the scene now.

How to do it…

I created a new function called spawnEmptyBody and added the following code to the MainScene.m file:

-(void)spawnEmptyBody{ CCNode *node = [[CCNode alloc]init]; CCPhysicsBody *body = [CCPhysicsBody bodyWithCircleOfRadius:10 andCenter:node.anchorPointInPoints]; body.type = CCPhysicsBodyTypeStatic; node.physicsBody = body; node.position = ccp(winSize.width * 0.5f, winSize.height * 0.7f); [_physicsWorld ...

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