Time for action – using the SoundManager class
In the
Game1.cs
file, add the following line as the last line in theLoadContent()
method:SoundManager.Initialize(Content);
Open the
ExplosionManager.cs
file and add the following as the last line of theAddExplosion()
method:SoundManager.PlayExplosion();
Open the
ShotManager.cs
file and add the following to the end ofFireShot()
:if (playerFired) { SoundManager.PlayPlayerShot(); } else { SoundManager.PlayEnemyShot(); }
Execute the game and enjoy the sound effects.
What just happened?
Using the SoundManager class is extremely simple. After it has been initialized, it only requires a single line to play any of our sound effects.
Because the class is static, all of the classes in our game simply "know" about it, and can use it without any further declaration.