Game Development Reference
In-Depth Information
The sounds added to the project can now be loaded up using the sound manager.
public Form1()
{
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
InitializeDisplay();
InitializeSounds();
// Added
InitializeTextures();
InitializeGameState();
The InitializeSound method will be responsible for loading in all the sound
files.
private void InitializeSounds()
{
_soundManager.LoadSound("effect", "soundEffect1.wav");
_soundManager.LoadSound("effect2", "soundEffect2.wav");
}
To test the sound manager, we really need some code that will let these sounds be
played. When OpenAL plays a sound, it returns an integer that is used to re-
ference the sound being played. For our sound manager we are going to wrap
that integer up in the Sound class; this gives it more context in the code. Instead
of just being a random integer, it's now a typed sound object. If there is an error
playing the sound, then minus one will be returned. Here's the Sound class that
will wrap up OpenAL's reference integer.
public class Sound
{
public int Channel { get; set; }
public bool FailedToPlay
{
get
{
// minus is an error state.
return (Channel == -1);
}
}
 
Search WWH ::




Custom Search