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.
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 on becoming active [[CDAudioManager sharedManager] setResignBehavior:kAMRBStopPlay autoHandle:YES]; //Initialize source container soundSources = [[NSMutableDictionary alloc] init]; //Add the sounds [self loadSoundEffect:@"bullet_fire_no_shell.caf" gain:1.0f]; [self loadSoundEffect:@"bullet_casing_tink.caf" gain:0...