I’ve created a button that toggles between on and off in my Options menu. Problem is, if I turn it off, then exit and return to the Options menu, it will read as on again, because of the way I’ve coded it. In other words, it’s state does not persist through scene transitions (I’m using Director Class, if this means anything). To make it work properly, I know I have to specify the button’s state on a global level, but I don’t know exactly how to do this.
Can anyone help?
My code is as follows:
local musicOn_btn = display.newImageRect("musicOn_btn.png", 343, 72);musicOn_btn:setReferencePoint(display.CenterReferencePoint);musicOn_btn.x = _W/2; musicOn_btn.y = 275; local musicOff_btn = display.newImageRect("musicOff_btn.png", 343, 72);musicOff_btn:setReferencePoint(display.CenterReferencePoint);musicOff_btn.x = _W/2; musicOff_btn.y = 275;musicOff_btn.isVisible = false function toggleMusicButton(event) if(event.phase == "ended") then if musicOn_btn.isVisible == true then musicOff_btn.isVisible = true musicOn_btn.isVisible = false; else musicOff_btn.isVisible = false musicOn_btn.isVisible = true; end endend musicOn_btn:addEventListener("touch", toggleMusicButton)musicOff_btn:addEventListener("touch", toggleMusicButton)[/code]Thanks in advance,Steven [import]uid: 79394 topic_id: 19896 reply_id: 319896[/import]
