I need help with adding sound off/on button to my game. In global variable lua file, I have the following:
local sounds = {}
sounds["select"] = audio.loadSound("sounds/select.mp3")
sounds["score"] = audio.loadSound("sounds/score.mp3")
G.playSound = function(name)
if sounds[name] ~= nil then
audio.play(sounds[name])
end
end
In games.lua file, I call the function as:
utils.playSound("score")
I have a soundon.png and soundoff.png files both in a sprite sheet (not sure if that is a good idea), all I am trying to implement is when you click the sound button, all sounds stops and it displays the soundoff image, vice versa. Thanks
I personally wouldn't use a sprite sheet. Just load both images and toggle their "isVisible" field. Then toggle a variable which would stop your sounds. Try something like this.
Now that we have our buttons working, we need to toggle the sound on and off.