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:
Open the
Bird.m
file and import theAudioManager.h
header file at the top as follows:#import "AudioManager.h"
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.The final file we...