Skip to Main Content
Learning iPhone Game Development with Cocos2D 3.0
book

Learning iPhone Game Development with Cocos2D 3.0

by Kirill Muzykov
June 2014
Beginner to intermediate content levelBeginner to intermediate
434 pages
9h 49m
English
Packt Publishing
Content preview from Learning iPhone Game Development with Cocos2D 3.0

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; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

James Goodwill, Wesley Matlock

Publisher Resources

ISBN: 9781782160144Supplemental Content