toadflax
toadflax

Reputation: 375

Change volume of SoundEffect Class

I have initialized a SoundEffect property like so:

private SoundEffect sound;

and it has been loaded in the Load() function like so:

sound = Content.Load<SoundEffect>("Jump15");

The sound plays fine, however it is too loud, and I've tried using SoundEffect.MasterVolume in the Load() function with different values but it doesn't seem to be changing the volume at all.

Please help!

Upvotes: 1

Views: 2151

Answers (1)

paste
paste

Reputation: 350

There's a version of the SoundEffect.Play() method that takes volume as a parameter. You can set the second and third arguments to zero.

sound = Content.Load<SoundEffect>("Jump15");
sound.Play(volume: 0.5f, pitch: 0.0f, pan: 0.0f);

Alternately you can create a sound effect instance and set the volume after the sound starts playing. This can be useful when you want to apply effects, like fading the sound in or out.

var instance = sound.CreateInstance();
instance.Volume = 0.5f;
instance.Play();

For more information, here's a nice tutorial on playing SoundEffects in XNA/MonoGame.

Upvotes: 3

Related Questions