Time for action – using the SoundManager class

  1. In the Game1.cs file, add the following line as the last line in the LoadContent() method:
    SoundManager.Initialize(Content);
  2. Open the ExplosionManager.cs file and add the following as the last line of the AddExplosion() method:
    SoundManager.PlayExplosion();
  3. Open the ShotManager.cs file and add the following to the end of FireShot():
    if (playerFired)
    {
        
        SoundManager.PlayPlayerShot();
    }
    else
    {
        
        SoundManager.PlayEnemyShot();
    }
  4. 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 ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.