Right then,
I’ve tried to simulate this as simply as possible. It prints to the console each thing its trying to do. Assume you don’t need my build settings and config.
So I have 4 lua files, main.lua (which runs my main parent scene), test.lua (The parent scene with 2 buttons - all the second one does is output text to the console for demonstrating the issue), overlay1.lua and overlay2.lua (each of which have a back button and pass control back to the parent.
When you run the program initially you can click the second button as many times as you like and it works.
If you click the first button the first overlay opens (which prevents the buttons on the parent from being clicked, as expected).
Closing overlay 1 runs some code on the parent (scene:resumeGame1()) and then runs overlay 2. Closing overlay 2 again returns control to the parent (scene:resumeGame2()), but from here on in no buttons can be clicked.
MAIN.LUA
--------------------------------------------------------------------------------- -- -- main.lua - The main startup shell -- --------------------------------------------------------------------------------- -- Load external Library's local composer = require("composer") --------------------------------------------------------------------------------- -- -- Main Scene Control -- --------------------------------------------------------------------------------- -- Start Test Screen composer.gotoScene( "test" )
TEST.LUA
--------------------------------------------------------------------------------- -- -- Test.lua - The Main Parent Screen -- --------------------------------------------------------------------------------- -- Load external Library's local composer = require("composer") local widget = require("widget") -- Load scene with same root filename as this file local scene = composer.newScene() local popupTransitionOptions = {isModal = true, effect = "fade", time = 300} --------------------------------------------------------------------------------- -- -- Scene Controls/Setup -- --------------------------------------------------------------------------------- -- Called when the scene's view does not exist -- INSERT code here to initialize the scene e.g. add display objects to 'sceneGroup', add touch listeners, etc function scene:create( event ) -- Required for composer to manage the scene local sceneGroup = self.view -- default to TopLeft anchor point for new objects display.setDefault( "anchorX", 0.0 ) display.setDefault( "anchorY", 0.0 ) button1 = widget.newButton({onPress=button1Clicked, onRelease=button1Selected, font="Arial", isEnabled=true, defaultFile="BackButton.png", overFile="BackButtonHover.png"}) button1.x = display.contentCenterX - 84 button1.y = display.contentCenterY + 335 sceneGroup:insert(button1) button2 = widget.newButton({onPress=button2Clicked, onRelease=button2Selected, font="Arial", isEnabled=true, defaultFile="BackButton.png", overFile="BackButtonHover.png"}) button2.x = display.contentCenterX + 84 button2.y = display.contentCenterY + 335 sceneGroup:insert(button2) -- restore anchor points for new objects to center anchor point display.setDefault( "anchorX", 0.5 ) display.setDefault( "anchorY", 0.5 ) return true end ---------- function scene:show( event ) -- Required for composer to manage the scene local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen -- Set screen title, buttons etc elseif phase == "did" then -- Called when the scene is now on screen -- INSERT code here to make the scene come alive e.g. start timers, begin animation, play audio, etc composer.removeHidden() end return true end ---------- function scene:hide( event ) -- Required for composer to manage the scene local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- INSERT code here to pause the scene e.g. stop timers, stop animation, unload sounds, etc.) elseif phase == "did" then -- Called when the scene is now off screen end return true end ---------- function scene:destroy( event ) -- Required for composer to manage the scene local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) -- INSERT code here to cleanup the scene e.g. remove display objects, remove touch listeners, save state, etc return true end -- Custom function for resuming the game from overlay 1 function scene:resumeGame1() -- Do Nothing, resume game print("CONTOL RETURNED TO PARENT FROM OVERLAY 1") print("RUNNING SECOND OVERLAY") -- Show the overlay composer.showOverlay( "overlay2", popupTransitionOptions ) return true end -- Custom function for resuming the game from overlay 2 function scene:resumeGame2() -- Do Nothing, resume game print("CONTOL RETURNED TO PARENT FROM OVERLAY 2") return true end -------------- -- Button 1 -------------- function button1Clicked( event ) print("BUTTON 1 CLICKED") return true end function button1Selected( event ) print("BUTTON 1 SELECTED") -- Show the overlay composer.showOverlay( "overlay1", popupTransitionOptions ) return true end -------------- -- Button 2 -------------- function button2Clicked( event ) print("BUTTON 2 CLICKED") return true end function button2Selected( event ) print("BUTTON 2 SELECTED") return true end --------------------------------------------------------------------------------- -- -- Listener Setup -- --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
OVERLAY1.LUA
------------------------------------------------------------------------------ -- -- Overlay1.lua - First Overlay -- ------------------------------------------------------------------------------ -- Load external Library's local composer = require("composer") local widget = require("widget") -- Load scene with same root filename as this file local scene = composer.newScene() function scene:create( event ) -- Required for composer to manage the scene local sceneGroup = self.view -- default to TopLeft anchor point for new objects display.setDefault( "anchorX", 0.0 ) display.setDefault( "anchorY", 0.0 ) button1 = widget.newButton({onPress=okButtonClicked, onRelease=okButtonSelected, font="Arial", isEnabled=true, defaultFile="BackButton.png", overFile="BackButtonHover.png"}) button1.x = display.contentCenterX - 84 button1.y = display.contentCenterY + 100 sceneGroup:insert(button1) -- restore anchor points for new objects to center anchor point display.setDefault( "anchorX", 0.5 ) display.setDefault( "anchorY", 0.5 ) return true end function scene:show( event ) -- Required for composer to manage the scene local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen -- Set screen title, buttons etc elseif phase == "did" then -- Called when the scene is now on screen -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent --reference to the parent scene object if ( phase == "will" ) then parent:resumeGame1() -- returning original passed in params end end --------------------------------------------------------------------------------- -- -- Event Handling -- --------------------------------------------------------------------------------- -------------- -- OK Button -------------- function okButtonClicked( event ) print("OK CLICKED") return true end function okButtonSelected( event ) print("HIDING OVERLAY 1") composer.hideOverlay( "fade", 100 ) return true end --------------------------------------------------------------------------------- -- -- Listener Setup -- --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
OVERLAY2.LUA
------------------------------------------------------------------------------ -- -- Overlay2.lua - Second Overlay -- ------------------------------------------------------------------------------ -- Load external Library's local composer = require("composer") local widget = require("widget") -- Load scene with same root filename as this file local scene = composer.newScene() function scene:create( event ) -- Required for composer to manage the scene local sceneGroup = self.view -- default to TopLeft anchor point for new objects display.setDefault( "anchorX", 0.0 ) display.setDefault( "anchorY", 0.0 ) button1 = widget.newButton({onPress=okButtonClicked, onRelease=okButtonSelected, font="Arial", isEnabled=true, defaultFile="BackButton.png", overFile="BackButtonHover.png"}) button1.x = display.contentCenterX - 84 button1.y = display.contentCenterY + 100 sceneGroup:insert(button1) -- restore anchor points for new objects to center anchor point display.setDefault( "anchorX", 0.5 ) display.setDefault( "anchorY", 0.5 ) return true end function scene:show( event ) -- Required for composer to manage the scene local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen -- Set screen title, buttons etc elseif phase == "did" then -- Called when the scene is now on screen -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent --reference to the parent scene object if ( phase == "will" ) then parent:resumeGame2() -- returning original passed in params end end --------------------------------------------------------------------------------- -- -- Event Handling -- --------------------------------------------------------------------------------- -------------- -- OK Button -------------- function okButtonClicked( event ) print("OK CLICKED") return true end function okButtonSelected( event ) print("HIDING OVERLAY 2") composer.hideOverlay( "fade", 100 ) return true end --------------------------------------------------------------------------------- -- -- Listener Setup -- --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene