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

  1. 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 the cocos2d.h header at the top as follows:

    #import "cocos2d.h"
  2. After this, add the following implementation of the playSoundEffect:withPosition...