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

Get Learning iPhone Game Development with Cocos2D 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.