Jump to content

Music Volume Question


Ninjadoodle
 Share

Recommended Posts

Hi @enpu

I can't seem to be able to set the music volume - just wondering whether it's something i'm doing wrong, or a bug ...

intro = new game.Music('intro.wav');
intro.loop = false;
intro.play();

then to set volume to 0 ...

game.Audio.musicVolume = 0;

This doesn't seem to do anything, yet it works correctly on Sounds.

Link to comment
Share on other sites

soundVolume and musicVolume attributes are used to set the initial volume.

If you want to dynamically change volume of a single sound, use the volume property.

intro.volume = 0.5;

If you want to mute sound, use mute and unmute functions

intro.mute();
intro.unmute();

 

Link to comment
Share on other sites

Depends on what are you trying to achieve?

If you want all your sounds to play at 50% volume, then add this to your config:

game.config = {
    audio: {
        soundVolume: 0.5
    }
};

Same works for music. If you want automatically all musics to be at 50% volume:

game.config = {
    audio: {
        musicVolume: 0.5
    }
};

 

Link to comment
Share on other sites

There is mute and unmute functions in Audio which you can use to mute and unmute all audio.

game.audio.mute(); // Mute all sounds and music
game.audio.unmute(); // Unmute all sound and music

I have just added also muteMusic, unmuteMusic, muteSound and unmuteSound functions to mute/unmute sounds and music separately.

game.audio.muteMusic(); // Mute music
game.audio.muteSound(); // Mute all sounds

game.audio.unmuteMusic(); // Unmute music
game.audio.unmuteSound(); // Unmute all sounds

There is also muted, mutedMusic and mutedSound boolean properties which you can use to check if something is muted or not

if (game.audio.mutedMusic) {
    // Do something if music is muted
}

 

Link to comment
Share on other sites

@enpu - Awesome, you're a legend ... I just have one more question. If I mute all SFX, does that mean that if I try to play a new one it will still play (or will it also be muted?).

The reason I was using what I thought was 'universal' volume, is that when I turned SFX off, they would stay off even if attempting to play a new one (because the volume was 0).

Mute sounds like it will just silence all current sounds, but not anything after that.

Link to comment
Share on other sites

If you want to do something (mute, set volume etc) only for currently playing sounds, there is sounds array in Audio. Just loop through it.

// Mute only currently playing sounds
for (var i = 0; i < game.Audio.sounds.length; i++) {
    game.Audio.sounds[i].mute();
}

Also you can access currently playing music from game.audio.music

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...