Game Development Reference
In-Depth Information
return new Sound(channel);
}
else
{
// Error sound
return new Sound(-1);
}
}
There are two PlaySound methods implemented here; one takes a flag to in-
dicate if the sound should be looped, the other takes one less parameter and
assumes the sound should only be played once by default. The PlaySound
method finds a free channel and loads the buffered data from the SoundSource
on to the channel. It then resets the default properties on the sound channel,
including the pitch and gain and the looping flag is set. This determines if the
sound will finish after being played once or if it just repeats. Finally it's told to
play the sound and a Sound object is returned.
The sound system is now working well enough to test. It can load files from the
disk and play them as needed. Here is a new test state that will demonstrate the
functionality.
class SoundTestState : IGameObject
{
SoundManager _soundManager;
double _count = 3;
public SoundTestState(SoundManager soundManager)
{
_soundManager = soundManager;
}
public void Render()
{
// The sound test doesn't need to render anything.
}
public void Update(double elapsedTime)
{
_count -= elapsedTime;
 
Search WWH ::




Custom Search