Hey
I have a menu screen with three buttons --> Play, Help and Settings.
When “Settings” is pressed, three sub-settings buttons pops out and one of them is audio on/off. When settings is clicked again, the sub-settings menu goes back in. I have a problem with audio on/off. The default is audio ON. When I tap on it to turn off the audio and when I click on settings to hide the Sub-settings menu, it works fine. But when after this, I click on settings again to allow the sub-settings menu to pop out, it shows both audio ON and OFF icon when it is supposed to show only audio OFF.
Here are my codes for the Settings button and the audio Buttons. (Sorry about the indentation of the codes… I don’t know why it becomes like this when I paste the codes here )
[lua]local touchStng = function(event) – this code is for settings (When clicked, the sub-settings menu pops out)
local obj = event.target
if event.phase == “ended” then
doanim(obj)
audio.play(sounds.popsound)
transition.to(abtBtn, {delay = 100, time = 100, alpha = 1 })
transition.to(soundonBtn, {delay = 300, time = 300, alpha = 1 })
transition.to(soundoffBtn, {delay = 300, time = 300, alpha = 1 })
transition.to(fbBtn, {delay = 500, time = 500, alpha = 1 })
transition.to(obj, {delay = 100, time = 100, alpha = 0 })
transition.to(stngBtn2, {delay = 100, time = 100, alpha = 1 })
obj.active = fasle
stngBtn2.alpha = 0
end
end[/lua]
[lua]local touchStng2 = function(event) – for settings (When clicked, the sub-settings menu goes back in)
local obj = event.target
if event.phase == “ended” then
doanim(obj)
audio.play(sounds.popsound)
transition.to(abtBtn, {delay = 500, time = 500, alpha = 0 })
transition.to(soundoffBtn, {delay = 300, time = 300, alpha = 0 })
transition.to(soundonBtn, {delay = 300, time = 300, alpha = 0 })
transition.to(fbBtn, {delay = 100, time = 100, alpha = 0 })
transition.to(obj, {delay = 100, time = 100, alpha = 0 })
transition.to(stngBtn, {delay = 100, time = 100, alpha = 1 })
obj.active = false
stngBtn.alpha = 0 end
end[/lua]
[lua]local touchSoundon = function(event) – to turn off the sound
local obj = event.target
if event.phase == “ended” then
doanim(obj)
audio.play(sounds.popsound)
obj.alpha = 0
obj.active = false
_G.sound = 0
audio.setVolume(_G.sound)
soundoffBtn.alpha = 1
transition.to(soundoffBtn, { time = 100, xScale = 1.3, yScale = 1.3 })
transition.to(soundoffBtn, { delay = 100, time = 300, xScale = 1, yScale = 1 }) – animate the button
soundoffBtn.active = true – make the off button active
settings.sound = 0
settings:save()
end
end[/lua]
[lua]local touchSoundoff = function(event)
local obj = event.target
if event.phase == “ended” then
doanim(obj)
audio.play(sounds.popsound)
obj.alpha = 0
obj.active = false
_G.sound = 1
audio.setVolume(_G.sound)
soundonBtn.alpha = 1
transition.to(soundonBtn, { time = 100, xScale = 1.3, yScale = 1.3 })
transition.to(soundonBtn, { delay = 100, time = 300, xScale = 1, yScale = 1 }) – animate the button
soundonBtn.active = true – make the on button active
settings.sound = 1 -
settings:save()
end
end[/lua]