Time for action – using the SoundManager class
In the
Game1.vb
file, add the following line as the last line in theLoadContent()
method:SoundManager.Initialize(Content)
Open the
ExplosionManager.vb
file, and add the following as the last line of theAddExplosion()
method:SoundManager.PlayExplosion()
Open the
ShotManager.vb
file and add the following to the end ofFireShot()
:If playerFired Then SoundManager.PlayPlayerShot() Else SoundManager.PlayEnemyShot() End If
Execute the game and enjoy the sound effects.
What just happened?
Using the SoundManager
module is very simple. After it has been initialized, we only need a single line of code to play any of our sound effects. Because we are using a module instead of a class, all of the classes in our game simply know about it, and can use it without any type of declaration beforehand.