Game Development Reference
In-Depth Information
Figure 11-4 . Three Sound effects keyframes with assigned audio files
If you publish and run the game, the menu logo and buttons should appear together with
the sound effects. This will be repeated if you exit the game and return to the main menu.
While this is neat and dandy, the sound-effects Timeline is not suitable for playing sounds
that need to be synchronized with game events, such as collisions or acceleration. It also
can't be used to play back looping sounds, which effectively rules out playing background
music through the Timeline—even when you put aside the fact that streaming audio
should be played back through ObjectAL's “long audio” background audio-playback
method (AVAudioPlayer).
Programming Audio Playback
Streaming audio and audio for game events need to be programmed, but that's rather easy
with ObjectAL's simplified interface provided by the OALSimpleAudio class. You'll
find the class reference here: http://kstenerud.github.io/ObjectAL-for-
iPhone/documentation/interface_o_a_l_simple_audio.html .
Playing Long/Streaming Audio
You generally have two ways of playing streaming audio. ObjectAL refers to streaming
audio as “background” music, usually abbreviated as “bg.” One way to play it is to pre-
load a piece of streaming audio and then play it. Or you can play a piece of music without
preloading it.
Preloading background tracks is only required if you need to start the playback at a very
specific point in time (in seconds) by using by the seekTime parameter. Or when you
need to be sure that the background track starts playing with no delay whatsoever—for
example, if it's a speech audio that needs to be lip-synched. Listing 11-1 shows an ex-
ample of playing a preloaded background track.
Search WWH ::




Custom Search