My question is the following:
How do I set up an array of sounds, so that a single button can play them? I have 5 wavs (sounds1.wav, sounds2.wav …. sounds5.wav), and ideally I would like for them to be random instead of a set order, but i have absolutely no idea if that is possible.
I am using this code as a basis:
var stream = TitleContainer.OpenStream("Sounds/sound1.wav");
var effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
Any help is appreciated. Thank you!
You could store them in an array of streams, but it’s only a good idea to do this if your
wavfiles aren’t big as you may surpass the 90mb memory usage limit if they are.You can then pick a random number, using the Random class, from
0to4(inclusive). This will mean that the chosen sound will be random instead of playing in any particular order.To play, you can just use your code above but replace the
FromStreamline to something like this: