Book Image

Cocos2d Game Development Blueprints

By : Jorge Jordán
Book Image

Cocos2d Game Development Blueprints

By: Jorge Jordán

Overview of this book

Table of Contents (15 chapters)
Cocos2d Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating your first physics


Now that you know the main actors that can intervene in a physics simulation, let's create our first space. Before getting down to work with physics, open the code files of this chapter from the code bundle where you'll find SnookerMunk_init.zip, which contains the initial project, and open it.

If you take a look at the project, you will realize that it just has one thing to highlight. Specifically, in AppDelegate.m, you will find this line:

CCSetupScreenOrientation: CCScreenOrientationPortrait,

We are just setting the portrait orientation of the project as this way the device will be more comfortable to hold.

Now let's add some physics. In GameScene.m, declare some private variables by adding the following lines:

    // Declare global variable for screen size
    CGSize _screenSize;

    // Declare the physics space
    CCPhysicsNode *_space;
    
    // Declare physics body
    CCPhysicsBody *_ball;
    // Declare ball node
    CCNode *_ballNode;
    
    // Declare...