Time for action – playing a sound at position
We are going to use the pan
parameter of the playEffect:
method to play the sound effect when a bird is hit at the position where the bird was actually hit. For example, when the bird is on the left-hand side of the screen and if it is hit, the sound will be louder in the left headphone, and when the bird is on the right-hand side of the screen and if it is hit, the sound will be played louder in the right headphone. The farther the bird is from the center of the screen, the higher the volume will be of the sound in the corresponding headphone. To test this, you will require headphones. Now perform the following steps:
Open the
AudioManager.h
file and add the following method declaration:-(void)playSoundEffect:(NSString *)soundFile withPosition:(CGPoint)pos;
Then, open the
AudioManager.m
file and import thecocos2d.h
header at the top as follows:#import "cocos2d.h"
After this, add the following implementation of the
playSoundEffect:withPosition...