X hits on this document

244 views

0 shares

0 downloads

0 comments

77 / 102

   if (audioManager.musicSound != null)

       audioManager.musicSound.Stop(true);

   // if the music sound exists

   if (audioManager.soundBank.ContainsKey(musicSoundName))

   {

       // get the instance and start it

audioManager.musicSound = audioManager.soundBank[musicSoundName];

       if (!audioManager.musicSound.IsLooped)

           audioManager.musicSound.IsLooped = true;

       audioManager.musicSound.Play();

   }

}

The above methods allows playing and stopping one of the sounds loaded using the “LoadSounds” method. The final method enables support for background, and will not be used in the course of this exercise.

171.

Add a final method to the AudioManager class by overriding the Dispose method:

C#

protected override void Dispose(bool disposing)

{

   try

   {

       if (disposing)

       {

           foreach (var item in soundBank)

           {

               item.Value.Dispose();

           }

           soundBank.Clear();

           soundBank = null;

       }

   }

   finally

   {

       base.Dispose(disposing);

   }

}

The above method disposes of all sound instances created by the AudioManager.

Now that we have support for both animation and sound, we can revisit the various classes created during the previous tasks in order to enhance their functionality.

Page | 77

Document info
Document views244
Page views244
Page last viewedTue Dec 06 12:46:53 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments