AudioManager

Description

The AudioManager will handle the sound and music of the game. Features concerning audio controls will be available such as volume manipulation. Will use the static MediaPlayer class from the XNA framework to play, stop, pause, and resume songs and sound effects.

Relationships

  • Window : The AudioManager is created by the Window as a static property
  • GameContentManager : gets all songs and sound effects from the GameContentManager
  • because this class will be used staticly, any class they needs to access this class to play audio can do so by passing in the name of the music/sound effect as a string that they want to play into the Play method to play audio.

Members

  • List<Song> musicList - stores all of the songs, such as background music
  • List<SoundEffect> soundList - stores all of the sound effects, suck as menu sounds and enemies abilities sounds like gun shot
  • float musicVolume - volume that the songs will play at
  • float sfxVolume - volume that sound effects will be played at, though a volume can be passed into the playSound method to play at a different volume
  • String currentSong - Represents the current song that is being played
  • bool isSongPaused - If the CurrentSong is paused or not
  • SoundEffectInstance[] soundsPlaying - An array which holds all the sound effects that are currently being played. These are stored so that if you have to stop the sound effects before they are done you can, such as when pausing the game
  • int maxSounds - An int representing the max number of sound effects that can be playing at once. Used for the size of the currently playing sound effects array.
  • bool isSongActive - If the currentSong is not stopped returns true

Methods

  • PlaySong
    • Plays a song based on the name passed in
  • PlaySound
    • will play a sound effect based on the name passed in
  • LoadSong
    • Loads a song and puts it in the musicList.
  • LoadSound
    • Loads a sound effect and puts it in the soundList. Sets the name of the sound effect to the name passed in as well.
  • StopMusic
    • Stops the CurentSong. If there is no song playing this does nothing. Should use when you are completely done with a song.
  • StopAllSoundEffects
    • This will loop through the array of currently playing SoundEffects and stop them all. Really only used when the player pauses the game.
  • PauseMusic
    • This will pause the current song if there is one and it's not already paused. Used when the game pauses.
  • PauseAllSoundEffects
    • This will pause all sound effects that are in the soundsPlaying array and aren't paused already
  • ResumeMusic
    • This will resume the current song if it was paused. Used when the game un-pauses.
  • ResumeAllSoundEffects
    • This will resume all sound effects in the soundsPlaying array that were paused
  • Update
    • checks for sound effects that are done playing and need to be disposed
    • checks if the media players volume is different from musicVolume and updates it if it is
  • getAvailableSoundIndex
    • this will return an available index in the currently playing sound effects array, or -1 if there isn't one
    • this is used when you play a sound effect and it needs to get added to the currently playing sound effect array so you know where you can put it or if there's not room for it.
  • ClearAllAudio
    • Clears out the musicList, soundList, and soundsPlaying array. Disposes any SoundEffectInstances that are in the soundsPlaying array first
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License