O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Playing sounds and music

Most games use a variety of sound effects and at most a few different background music tracks. CocosDenshion is the audio library built into Cocos2d. It provides a number of features including the SimpleAudioEngine API. In this recipe, we will use this API to play sounds and music.

Playing sounds and music

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe.

How to do it...

Execute the following code:

#import "SimpleAudioEngine.h" @implementation Ch6_SoundsAndMusic -(CCLayer*) runRecipe { //Initialize the audio engine sae = [SimpleAudioEngine sharedEngine]; //Background music is stopped on resign and resumed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required