Using audio in a game

While SimpleAudioEngine may be simple, it is efficient enough to be used in any type of game. In this recipe, we will add sounds and music to the Bullets demo from Chapter 4, Physics.

Using audio in a game

Getting ready

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

How to do it...

Execute the following code:

#import "Ch4_Bullets.h" #import "SimpleAudioEngine.h" @interface Ch6_AudioInGame : Ch4_Bullets /* CODE OMITTED */ @end @implementation Ch6_AudioInGame -(CCLayer*) runRecipe { [super runRecipe]; //Initialize the audio engine sae = [SimpleAudioEngine sharedEngine]; //Background music is stopped on resign and resumed ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.