Ninjadoodle Posted June 6, 2018 Share Posted June 6, 2018 Hi @enpu I've been looking through the docs, and it looks like both sounds and music have a volume property. I know how to adjust volume for a specific sound, but I'm trying to make SFX and MUSIC ON/OFF buttons. Is there a way I can set the volume for all SFX / MUSIC? PS. I know I can do game.audio.playSound('sound.m4a', [volume]) ... but I'm hoping to not have to do it for every sound + I don't think it will change the volume when the sound is already playing. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
8bitdna Posted June 6, 2018 Share Posted June 6, 2018 Hi @Ninjadoodle, Looking through the engine sourcecode here: https://github.com/ekelokorpi/panda-engine/blob/master/src/engine/audio.js I see there is a 'stopAll' function which I think if you call that will silence everything? Pete Quote Link to comment Share on other sites More sharing options...
8bitdna Posted June 6, 2018 Share Posted June 6, 2018 I think you call it as follows... game.audio.stopAll(); Looks like there is 'toggle', 'mute' and 'unmute' in the audio class as well which might help? Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted June 6, 2018 Author Share Posted June 6, 2018 Hi @8bitdna Thanks for that, but I’m still hoping there is a univeral volume for sfx and one for music. Using stopAll(), will stop all the sounds currently playing, when clicking the SoundFX OFF button, for example. However, any new sounds will still play as normal. I know I can play all new sound effects with my own volume variable, just wondering if there is a simpler way. For example set the whole music channel to 0 volume and set the who SFX channel to 0 volume. Quote Link to comment Share on other sites More sharing options...
8bitdna Posted June 6, 2018 Share Posted June 6, 2018 Ahhh, I see what you mean. @enpu is your man Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
8bitdna Posted June 6, 2018 Share Posted June 6, 2018 Actually, another look in the audio class and I see two attributes which look like they might be what yours after: /** Initial music volume (0-1). @attribute {Number} musicVolume @default 1 **/ musicVolume: 1, /** Initial sound volume (0-1). @attribute {Number} soundVolume @default 1 **/ soundVolume: 1, Maybe setting those will do the trick? Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted June 6, 2018 Author Share Posted June 6, 2018 Hi @8bitdna Thanks, I found those yesterday, but can’t seem to find a way to access them. I’ve tried game.audio.soundVolume = 0, but no luck. I think I’m missing something simple lol. Quote Link to comment Share on other sites More sharing options...
8bitdna Posted June 6, 2018 Share Posted June 6, 2018 game.Audio.soundVolume = 0; Does that work? Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted June 6, 2018 Author Share Posted June 6, 2018 @8bitdna - LOL, yup that works - I knew it was something stupidly simple! Thanks heaps Quote Link to comment Share on other sites More sharing options...
8bitdna Posted June 6, 2018 Share Posted June 6, 2018 Not stupid at all, I only spotted how to do it looking through the engine source code and saw a line with it in. I assumed the same as you in the first instance! I'd like to be able to get a little more fluent with the engine and JS so I can understand things better. Some parts of JS whilst powerful are a pain to me at least Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
enpu Posted June 7, 2018 Share Posted June 7, 2018 @Ninjadoodle Like any other class attributes, you can also set musicVolume and soundVolume values in your game.config game.config = { audio: { musicVolume: 0.5, soundVolume: 1 } }; Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted June 7, 2018 Author Share Posted June 7, 2018 @enpu - I got confused with the capitalization ... Instead of game.Audio.soundVolume = 0; I was trying game.audio.soundVolume = 0; Thanks! 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.