Time for action – preloading sound effects
Sound effects are typically much smaller than music files, and using formats such as Core Audio Format (CAF) will decrease the time used to decode the on-disk file into memory and prepare it for playing.
Note
Remember that sound effects are decoded and played on CPU, so we should avoid using too many heavily compressed formats such as MP3 for sound effects. This is why I mention different formats such as CAF. Such formats take more space on the disk, but are easier to decode. Of course, for a simple game like ours, we don't have to worry about this.
However, if you want to make sure that there is no delay when the sound effect is played for the first time, you need to preload it. Let's perform the following steps:
Open the
AudioManager.h
file and add the following#define
statements at the top, right above the@interface
declaration as follows:#define kSoundArrowShot @"arrow_shot.wav" #define kSoundBirdHit @"bird_hit.mp3" #define kSoundWin ...