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 more birds

We are going to add more Bird objects to fly around. To do this, we're going to replace our _bird variable with an array and write some code to spawn the birds:

  1. Open the GameScene.m file and remove the _bird variable. Instead, add two new instance variables to the GameScene class, as shown in the following code:
    @implementation GameScene
    {
        CCSpriteBatchNode *_batchNode;
        
        Hunter  *_hunter;
    
        float _timeUntilNextBird;
        NSMutableArray *_birds;
    }
  2. Add following method somewhere below the update: method:
    -(void)spawnBird { //1 CGSize viewSize = [CCDirector sharedDirector].viewSize; //2 int maxY = viewSize.height * 0.9f; int minY = viewSize.height * 0.6f; int birdY = minY + arc4random_uniform(maxY - minY); int birdX = viewSize.width ...
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