Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning iPhone Game Development with Cocos2D 3.0

You're reading from   Learning iPhone Game Development with Cocos2D 3.0 Harness the power of Cocos2D to create your own stunning and engaging games for iOS

Arrow left icon
Product type Paperback
Published in Jun 2014
Publisher
ISBN-13 9781782160144
Length 434 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Kirill Muzykov Kirill Muzykov
Author Profile Icon Kirill Muzykov
Kirill Muzykov
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. All About Cocos2D FREE CHAPTER 2. Hello Cocos2D 3. Cocos2D – Under the Hood 4. Rendering Sprites 5. Starting the Action 6. Rendering Text 7. Animations and Particle Systems 8. Adding Sound Effects and Music 9. User Interface and Navigation 10. Physics 11. Working with Tile Maps A. Pop Quiz Answers Index

Time for action – adding ground to the scene

Most of the times you'll want your object to stay on the screen instead of falling into the abyss. So, let's add some ground that will stop the stone from falling further. Refer to the following steps:

  1. Open the PhysicsScene.m file and add the _ground instance variable:
    @implementation PhysicsScene
    {
       //..skipped..
    
       CCSprite *_ground;
    }
  2. Then, before adding the ground sprite, add one more z-order #define statement, between kBackgroundZ and kObjectsZ as shown in the following code:
    #define kBackgroundZ    10
    #define kGroundZ        15
    #define kObjectsZ       20
  3. Now, add the addGround method as follows:
    -(void)addGround
    {
        //1
        _ground = [CCSprite spriteWithImageNamed:@"ground.png"];
        
        //2
        CGRect groundRect;
        groundRect.origin = CGPointZero;
        groundRect.size = _ground.contentSize;
        
        //3
        CCPhysicsBody *groundBody = 
          [CCPhysicsBody bodyWithRect:groundRect cornerRadius:0];
        
        /...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image