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.
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 on become active [[CDAudioManager sharedManager] setResignBehavior:kAMRBStopPlay autoHandle:YES]; //Initialize source container soundSources = [[NSMutableDictionary alloc] init]; //Add the sounds [self loadSoundEffect:@"crazy_chimp.caf"]; [self loadSoundEffect:@"rapid_gunfire.caf"]; [self loadSoundEffect:@"howie_scream...