Game Development Reference
In-Depth Information
{
// existing code omitted for brevity ...
[[OALSimpleAudio sharedInstance] playEffect:@"Audio/
menu-sfx.caf"];
}
The menu sound effect is small and not time-critical, so it's not a problem to play it
without preloading. But unlike background tracks, sound effects played during gameplay
should always be preloaded. Otherwise, the first time a specific sound effect plays, there
may be a small but possibly noticeable hiccup. Imagine if the player jumps, shoots, or gets
hit and the game freezes for a tenth of a second the first time this happens because the
sound effect needed to be loaded from relatively slow flash memory. You'll want to avoid
that scenario even if the sound effects used in this particular project will most likely load
quickly enough that you will not notice a delay.
Unfortunately, there's no way to assign audio files to a given scene and then tell it to pre-
load all associated audio files. You essentially have to keep a list of sound effects used by
a given scene, or by the game overall, and then preload those sound effects one after an-
other. Fortunately, in this project you're using only three gameplay sound effects, and
they're consistently named. (See Figure 11-2 .)
Add the code highlighted in Listing 11-5 at the end of the presentGameScene method
in SceneManager.m .
Listing 11-5 . Preloading all splat sound effects
+(void) presentGameScene
{
// existing code omitted for brevity ...
OALSimpleAudio* audio = [OALSimpleAudio sharedInstance];
for (int i = 1; i <= 3; i++)
{
NSString* path = [NSString stringWithFormat:@"Audio/
splat%i.caf", i];
[audio preloadEffect:path];
}
}
Here the path string for every audio file is generated within the for loop. It helps to have
similar audio files numbered in the same way so that if you were to add a dozen more, you
Search WWH ::




Custom Search