Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – fixing the hunter movement


The good thing that comes from the fact that physics simulation and rendering are independent is that we can create physics bodies with just a few lines of code without any images, using just the CCNode class.

In this section, we're going to add the addBoundaries method, which will add two invisible physics bodies to the sides of the screen so that the hunter doesn't fall off the screen. In addition to this, we're going to adjust the friction of the hunter's physics body so that he doesn't slide too much.

  1. Open the PhysicsScene.m file and add the addBoundaries method, as shown in the following code:

    -(void)addBoundaries
    {
        CGSize viewSize = [CCDirector sharedDirector].viewSize;
        CGRect boundRect = 
          CGRectMake(0, 0, 20, viewSize.height * 0.25f);
        
        CCNode *leftBound = [CCNode node];
        leftBound.position = 
          ccp(0, _ground.contentSize.height + 30);
        leftBound.contentSize = boundRect.size;
        
        CCPhysicsBody *leftBody...