Game Development Reference
In-Depth Information
Each time they blink off, a quick little click sound is made. When you run this example, you will also
hear a background sound track that plays continuously while the game is running. The switch on the
upper left controls whether such sound effects, like the blinking sound, should be heard regardless
of other audio being played. Obviously, we would not include a switch like this on the screen while
your game is playing, but it might be a good option on a setting screen someplace, probably
defaulting to OFF.
As mentioned, there is a background sound track that plays in addition to the sound effects. As
you will see in the following sections, these two types of audio are handled differently to make the
developer's life a little easier.
The following sections will go over this example piece by piece, highlighting how sound effects
are played
Setting up the GameController
Like many of the examples in this game, we start by extending GameController to specify our game
specific features—the business logic of the game, if you will. Listing 11-5 shows how we set up this
example.
Listing 11-5. doSetup (ViewController.m)
-(BOOL)doSetup{
if ([super doSetup]){
[self setGameAreaSize:CGSizeMake(480, 320)];
[self setIsPaused: NO];
NSMutableArray* classes = [NSMutableArray new];
[classes addObject:[Powerup class]];
[self setSortedActorClasses:classes];
viper = [Viper viper:self];
[self addActor: viper];
[self prepareAudio: AUDIO_POWERUP_BLINK];
[self prepareAudio: AUDIO_GOT_POWERUP];
[self playBackgroundAudio: AUDIO_BC_THEME];
return YES;
}
return NO;
}
In Listing 11-5, we see our standard GameController setup code. We specify the size of the game
area, indicate that we want to keep track of Powerup actors, and we create and add a Viper . The
last few things we do in doSetup is to set up the audio we want to play. We call prepareAudio :, then
pass in the NSString constants AUDIO_POWERUP_BLINK and AUDIO_GOT_POWER . We will look at the task
prepareAudio : shortly. For completeness, let's take a quick look at the three NSString constants that
are defined in Listing 11-6.
 
Search WWH ::




Custom Search