Fun Infused Games  |   Smooth Operator RSS 

  Home   |    Archive   |    Subscribe   |    Search   |    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


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