Game Development Reference
In-Depth Information
m_AudioBuffer.reset(buffer);
Play(m_Volume, m_isLooping);
}
The VOnUpdate method monitors the sound effect as it ' s being played. Once it is
finished, it kills the process and releases the audio buffer. If the sound is looping, it
will play until some external call kills the process. Again, you don
'
t have to do it this
'
way in your game. Perhaps you
d rather have the process hang out until you kill it
explicitly:
void SoundProcess::VOnUpdate(const int deltaMilliseconds)
{
// Call base
Process::VOnUpdate(deltaMilliseconds);
if ( IsDead() && IsLooping() )
{
Replay();
}
}
This class overloads the VKill() method to coordinate with the audio system. If the
process is going to die, so should the sound effect.
void SoundProcess::VKill()
{
if ( IsPlaying() )
Stop();
Process::VKill();
}
Notice that the base class
s VKill() is called at the end of the method, rather than
the beginning. You can look at VKill() similar to a destructor, which means this
calling order is a safer way to organize the code.
As advertised, the remaining methods do nothing more than pass calls into the
IAudioBuffer object.
'
bool SoundProcess::IsPlaying()
{
if ( ! m_handle || ! m_AudioBuffer )
return false;
return m_AudioBuffer->VIsPlaying();
}
Search WWH ::




Custom Search