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 – playing the remaining sound effects


We have added all the sound effects files to our project previously, so what we are going to do now is just add some code to play them. We need to add the code in three places: when the arrow hits the bird, when we lose, and when we win the game.

Let's start making changes by performing the following steps:

  1. Open the Bird.m file and import the AudioManager.h header file at the top as follows:

    #import "AudioManager.h"
  2. Next, find the removeBird: method and add the corresponding sound effect that will be played when the bird is hit by an arrow:

    -(int)removeBird:(BOOL)hitByArrow
    {
        //..skipped
        if (hitByArrow)
        {
            //..skipped..
            
            [[AudioManager sharedAudioManager]
              playSoundEffect:@"bird_hit.mp3"];
        }
        //..skipped..
    }

    Note

    Note that I have used the file named bird_hit.mp3 (which is in the .mp3 file format); if your file is named differently, then you have to adjust that line of code.

  3. The final file we...