Ninjadoodle Posted July 19, 2018 Share Posted July 19, 2018 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. Quote Link to comment Share on other sites More sharing options...
enpu Posted July 19, 2018 Share Posted July 19, 2018 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(); Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 19, 2018 Author Share Posted July 19, 2018 Hi @enpu Thanks, I will fix this for the music. In regards to sfx however, wouldn't I need to use soundVolume? Otherwise I would have to change the volume / mute all my sfx separately. Quote Link to comment Share on other sites More sharing options...
enpu Posted July 19, 2018 Share Posted July 19, 2018 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 } }; Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 19, 2018 Author Share Posted July 19, 2018 @enpu I'm trying to setup SFX and MUSIC On/Off buttons, so from what I understand - it needs to be done one by one? Quote Link to comment Share on other sites More sharing options...
enpu Posted July 19, 2018 Share Posted July 19, 2018 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 } Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 19, 2018 Author Share Posted July 19, 2018 @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. Quote Link to comment Share on other sites More sharing options...
enpu Posted July 19, 2018 Share Posted July 19, 2018 muteSound will mute all current sounds as well as any sounds that you play after that. Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 19, 2018 Author Share Posted July 19, 2018 @enpu - Thank you very much for adding this, as it makes the whole setting menu design a lot easier Really appreciate it! Quote Link to comment Share on other sites More sharing options...
enpu Posted July 19, 2018 Share Posted July 19, 2018 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 Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 19, 2018 Author Share Posted July 19, 2018 @enpu - Awesome, thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.