Hello Guys, I have a question , How can I put or remove audio for my game, from the menu, for people who wants to game with audio or without audio from beginning.
Thanks.
Hello Guys, I have a question , How can I put or remove audio for my game, from the menu, for people who wants to game with audio or without audio from beginning.
Thanks.
For this, I would suggest that you create a standard switch button (you can use the newSwitch widget if you prefer), and then set the master audio volume to 0 to mute all sounds.
[lua]
audio.setVolume( 0.0 ) – set the master volume
[/lua]
Or, if you prefer, you can build a more “complex” method where audio doesn’t even play if the audio setting from the menu is turned off. This would ultimately be a more efficient method (performance), but it depends on how many sound effects you’ll be playing, and the size/format of them. If you only have a few sound effects to enhance the app, an overall volume mute is probably fine.
Hope this helps,
Brent
Hi!
What Brent says could have saved me a lot of time in one of my latest games…
I created a preference value to keep track of the sound on/off option on my main.lua file
if not preference.getValue("musicIsOn") then preference.save{ musicIsOn = true } preference.save{ fxIsOn = true } end
and whenever I played a sound effect file or music, I would check if that value was active:
function playClickSound() if preference.getValue("fxIsOn") then audio.play(buttonClickSound) end end
Cheers!
Hello thanks for helping me,this function remove all the audio for the game? because I put the audio cancel and cancel only the music but not the sound effect
Hello paytopwn, I put the new swith method, but cancel all the audio and I cant the audio play again,how I can make it work correctly?
Thanks.
Brent , Thanks for your help ,this code works perfectly for me!!!
Well. the fact was that you have to control the way you play all your elements using my method. I think Brent’s method is simpler and better!
Cheers
For this, I would suggest that you create a standard switch button (you can use the newSwitch widget if you prefer), and then set the master audio volume to 0 to mute all sounds.
[lua]
audio.setVolume( 0.0 ) – set the master volume
[/lua]
Or, if you prefer, you can build a more “complex” method where audio doesn’t even play if the audio setting from the menu is turned off. This would ultimately be a more efficient method (performance), but it depends on how many sound effects you’ll be playing, and the size/format of them. If you only have a few sound effects to enhance the app, an overall volume mute is probably fine.
Hope this helps,
Brent
Hi!
What Brent says could have saved me a lot of time in one of my latest games…
I created a preference value to keep track of the sound on/off option on my main.lua file
if not preference.getValue("musicIsOn") then preference.save{ musicIsOn = true } preference.save{ fxIsOn = true } end
and whenever I played a sound effect file or music, I would check if that value was active:
function playClickSound() if preference.getValue("fxIsOn") then audio.play(buttonClickSound) end end
Cheers!
Hello thanks for helping me,this function remove all the audio for the game? because I put the audio cancel and cancel only the music but not the sound effect
Hello paytopwn, I put the new swith method, but cancel all the audio and I cant the audio play again,how I can make it work correctly?
Thanks.
Brent , Thanks for your help ,this code works perfectly for me!!!
Well. the fact was that you have to control the way you play all your elements using my method. I think Brent’s method is simpler and better!
Cheers