Book Image

Mastering Cocos2d Game Development

By : Alex Ogorek
Book Image

Mastering Cocos2d Game Development

By: Alex Ogorek

Overview of this book

Table of Contents (15 chapters)
Mastering Cocos2d Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Modifying the sound effect on the fly


One thing that's so cool about using OALSimpleAudio (and was also true about SimpleAudioEngine) is that you can modify how the audio file sounds when it gets played back to the user. For example, if you wish to have a series of coins collected, and each coin collected in rapid succession plays a slightly higher-pitched sound than the previous one, you can simply modify the pitch based on how many coins were collected.

The volume (or gain), pitch, and pan

With one simple call that adds a few parameters to the default playEffect method, you can modify the loudness of the effect, the pitch of the sound effect, and where in the speakers your effect plays. You can do so with the following code:

//volume range: 0.0 to 1.0
//pitch range: 0.0 to inf (1.0 is normal)
//pan range:  -1.0 to 1.0 (far left to far right)
//loop:  If YES, will play until stop is called on the sound
[[OALSimpleAudio sharedInstance] playEffect:@"soundEffect.mp3" volume:1 pitch:1 pan:1 loop...