Fun Infused Games  |   Smooth Operator

  Home   |    Archive   |    About
A Simple SoundBank Class for Windows Phone 7
Date 3/22/2011    Tags WP7    (0)

When you convert your XBLIGs to Windows Phone 7, you will find yourself without XACT support. For me this meant a ton of "soundBank.PlayCue()" calls that would no longer work. Rather than go through the tedious task of replacing them all with new SoundEffect objects, I created my own SoundBank class that allows me to use the calls exactly as they were but plays then in a WP7 kind of way. This class certainly doesn't encapsulate all the functionality of SoundBank but it does give you enough to play your cues.

In the constructor for the following class you pass in an instance of your ContentManager object. Inside the constructor is where you can load all your sounds (add the wave files to your content project). The constructor adds the sounds to a dictionary object. The first string will be the name you would use in your PlayCue() method in your XBLIG version.

Once you load your sounds, just call PlayCue() the same as you used to. For instance if I wanted to play my AsteroidDestroyed sound, I just call soundBank.PlayCue("AsteroidDestroyed").

public class SoundBank
{
    private Dictionary<string, SoundEffect> sounds;

    public SoundBank(ContentManager content)
    {
        sounds = new Dictionary<string, SoundEffect>();

        sounds.Add("AsteroidDestroyed", content.Load<SoundEffect>("Audio\\AsteroidDestroyed"));
        sounds.Add("Awardment", content.Load<SoundEffect>("Audio\\Awardment"));
    }

    /// <summary>
    /// Play a sound.
    /// </summary>
    public void PlayCue(string cueName)
    {
        if (sounds.ContainsKey(cueName))
        {
            sounds[cueName].Play();
        }
    }
}



This article has been view 1596 times.


Comments

No comments for this article.


Add Comments

Name *
Website
  Name the animal in the picture below:

*  
Comment *
Insert Cancel
Things To Click


Tags
Video Games (7)  Trivia or Die (3)  SQL (1)  iOS (3)  Game Dev (11)  Advise (14)  PC (1)  World of Chalk (2)  FIN (20)  Abduction Action! (27)  XBLIG (32)  Abduction Action (1)  Nastier (4)  ASP.net (18)  Absurd (2)  Volchaos (11)  Web (19)  Fin (1)  XNA (40)  Rant (50)  Cool (2)  Visual Studio (1)  Trivia Or Die (1)  Xbox (1)  C# (14)  Sports (11)  Design (2)  Development (13)  Hypership (28)  WP7 (8)  VolChaos (1)  Nasty (34)  Abdction Action! (1)