O'Reilly logo

Learning iPhone Game Development with Cocos2D 3.0 by Kirill Muzykov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required