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 to a game scene

Before we add any other objects, we need to prepare the scene to use physics.

Getting started

Once again, I have created a new project for this chapter. You know the standard operating procedure by now. So, create a new project and make the necessary changes to the project.

How to do it…

In the MainScene.h file, we will add a new variable of the CCPhysicsNode type named _physicsWorld. All the physics objects that we create in a game must be added to this henceforth. We will run the following:

CCPhysicsNode *_physicsWorld;

Next, in the init function, we will add the following:

winSize = [[CCDirector sharedDirector]viewSize]; CGPoint center = CGPointMake(winSize.width/2, winSize.height/2); self.contentSize = winSize; CCSprite* ...

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