Search code examples
c#xna

XNA sound effect


I have a little problem with a sound effect. It doesn't function well because when I play it is played around 500000 times in two seconds. Take a look look here:

SoundEffect thunder;
thunter=Content.Load<SoundEffect>("thunder");

foreach (flash flash in flashes)
   if(flash.visible==true)
       if (time >1 && time <3)
            thunder.Play(); //now it sounds bad because it is played a lot of times.. I want it to be played only once! (the sound is 5 sec long)

Solution

  • Hmm. Could it be as simple as this:

    foreach (var flash in flashes)
       if (flash.visible && time > 1 && time < 3)
       {
            thunder.Play();
            break; // play sound only once
       }