without seeing most or all of your code, it is hard for me to answer the new error you mention.
So here is a complete little app that shows a plain screen for a game-scene. It has a pause button. Press the pause button and the pause-overlay appears and has 2 buttons(Resume and Restart).
Click either one, and the ‘scene:hide’ sends to the game-scene either ‘RESUME’ or "RESTART’.
Create a new app for testing and use these 3 segments below to make a main.lua, gameScene.lua, and pauseOvly.lua. Just cut and paste in the code below into the 3 files. Jus the sure to have button images that are named the same as in my sample code.
Run the app and you should see how it works, and from that should be able to see how to apply that to your code.
If not, you may have to post a fair amount of your code for anyone to see what might be wrong. But, i think if you run this sample app you will likely see how to make everything work.
– main.lua
local composer = require( "composer" ) local scene = composer.newScene() display.setStatusBar( display.HiddenStatusBar ) composer.gotoScene("gameScene", {time=550, effect="crossFade"})
– gameScene.lua
composer = require('composer') local widget = require('widget') scene = composer.newScene() centerX = display.contentCenterX centerY = display.contentCenterY W = display.contentWidth H = display.contentHeight local gameSceneTitle local pauseBtn local statusText local function resumeGame() statusText.text = "GAME IS RESUMING" end local function restartLevel() print("restart the level") statusText.text = "RESTARTING THE LEVEL" end local function onPause(e) if e.phase == "ended" then local pauseOptions = { effect = "fade", time = 400, isModal = true } composer.removeHidden() composer.showOverlay( "pauseOvly", pauseOptions ) end end function scene:create(e) local sceneGroup = self.view local background = display.newRect(centerX,centerY, W,H) background:setFillColor(.1, .7, .1) background.x = centerX background.y = centerY pauseBtn = widget.newButton( { width = 200, height = 25 , id = 1, defaultFile = 'Images/pause.png', overFile = 'Images/pause\_dn.png', onEvent = onPause } ) pauseBtn.x = centerX pauseBtn.y = centerY - 100 statusText = display.newText("\*\*\*\*\*" ,centerX, H \* .2, nil, 18) statusText:setFillColor(0,0,0) sceneGroup:insert(background) sceneGroup:insert(pauseBtn) sceneGroup:insert(statusText) gameSceneTitle = display.newText('The Great Game', centerX, H \* .125) sceneGroup:insert(gameSceneTitle) end function scene:show(e) local phase = e.phase if "did" == phase then end end function scene:endPause(flag) print(" flag is " , flag) if flag == "RESUME" then resumeGame() elseif flag == "RESTART" then restartLevel() end end scene:addEventListener('create',scene) scene:addEventListener('show',scene) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
– pauseOvly.lua
composer = require('composer') local widget = require('widget') scene = composer.newScene() local centerX = display.contentCenterX local centerY = display.contentCenterY local W = display.contentWidth local H = display.contentHeight local restartLevelBtn local resumeBtn local flag = "RESUME" local pauseText local function onRestart(e) if e.phase == 'ended' then flag = "RESTART" composer.hideOverlay("fade", 400) end end local function onResume(e) if e.phase == 'ended' then flag = "RESUME" composer.hideOverlay("fade", 400) end end function scene:create(e) local sceneGroup = self.view local background = display.newRect(centerX,centerY, W,H) background.x = centerX background.y = centerY sceneGroup:insert(background) restartLevelBtn = widget.newButton( { width = 200, height = 25 , id = 1, defaultFile = 'Images/restart.png', overFile = 'Images/restart\_dn.png', onEvent = onRestart } ) restartLevelBtn.x = centerX restartLevelBtn.y = centerY - 100 sceneGroup:insert(restartLevelBtn) resumeBtn = widget.newButton( { width =200, height = 25, id = 2, defaultFile = 'Images/resume.png', overFile = 'Images/resume\_dn.png', onEvent = onResume } ) resumeBtn.x = centerX resumeBtn.y = centerY pauseText = display.newText("game is paused" ,centerX, H \* .2, nil, 18) pauseText:setFillColor(0,0,0) sceneGroup:insert(pauseText) sceneGroup:insert(resumeBtn) end function scene:show(e) local phase = e.phase if "did" == phase then end end function scene:hide( e ) local parent = e.parent if ( e.phase == "will" ) then elseif ( e.phase == "did" ) then parent:endPause(flag) end end scene:addEventListener('create',scene) scene:addEventListener('show',scene) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
Good luck
Bob