I’m trying to add the very simple pause menu as overlay to my “gamemode.lua”. I made this from guide about composer and showOverlay/hideOverlay features, but missing something in the scene logic.
I can see that “pause.lua” loaded and show text’s line, but they are not interact with “tap” event.
In “gamemode.lua” I have:
local function GamePause () --this before "function scene:create( event )" local options = { isModal = true, effect = "fade", time = 400 } physics.pause() timer.pause () composer.showOverlay( "pause", options ) end local function GameResume () physics.resume () timer.resume () end -- PauseButton = display.newRect( different options ) --this inside "function scene:create( event )" PauseButton:addEventListener ("tap", tapPauseButton)
in “pause.lua” I have this:
local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------- print("U are in the pause overlay") local pauseGroup local function gotoMenu() composer.gotoScene( "menu" ) -- This command should work, but it doesnt too end local function gotoGame () composer.hideOverlay( "fade", 400 ) end -- ----------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- function scene:create( event ) -- create() local sceneGroup = self.view print("U are in the scene:create( event ) part") pauseGroup = display.newGroup() -- Display group for the background image sceneGroup:insert( pauseGroup ) local MenuBackground = display.newImageRect( pauseGroup, "MenuBackground2.png", display.actualContentWidth, display.actualContentHeight ) MenuBackground.x = display.contentCenterX MenuBackground.y = display.contentCenterY local buttonBackToMenu = display.newText( sceneGroup, "Back To Menu", display.contentCenterX, 0.3\*display.actualContentHeight, native.systemFont, 100 ) buttonBackToMenu:setFillColor( 0, 0.294, 0.518 ) buttonBackToMenu:addEventListener( "tap", gotoMenu ) local buttonContinue = display.newText( sceneGroup, "Continue", display.contentCenterX, 0.35\*display.actualContentHeight+50, native.systemFont, 100 ) buttonContinue:setFillColor( 0, 0.294, 0.518 ) buttonContinue:addEventListener( "tap", gotoGame ) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end
-- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) parent:GameResume() elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene