Composer: can't hide overlay

I’m struggling to hide an overlay scene. It’s not actually a pause button - doesn’t stop the game, doesn’t reset it - simply shows some pictures on top. One of them is clickable and it’s supposed to hide the scene. However, it does not.

Also, objects in the parent scene still respond to clicks, even though I’ve set isModal as “true”. 

I’ve already seen the template and some examples, but it didn’t help.

I would be greatful to recieve any responce.

main.lua:

local composer = require("composer") local function pause(event) local goPauseOptions = { effect = "fade", time = 500, isModal = true, } composer.showOverlay( "pause", goPauseOptions ) end pauseBtn:addEventListener("tap", pause) return scene

pause.lua:

local composer = require( "composer" ) local scene = composer.newScene() local pauseexit local function closePause (event) print("There") composer.hideOverlay( "fade", 400 ) end function scene:create(event) local sceneGroup = self.view ----background and resume button----- pauseexit:addEventListener("tap", closePause ) end scene:addEventListener( "create", scene ) return scene

most likely your taps are going through because there is no return value.

local function closePause (event) print("There") composer.hideOverlay( "fade", 400 ) return true end

Thanks for the answer, but it didn’t work. I tried adding return true, but the result is the same for some reason. It does detect tap, but overlay is stell there. Sorry if it’s a stupid question, but I’ve been struggling for a few days now.

I’ve also tried “composer.removeScene()” in “scene:hide”, but it did nothing.

composer.gotoScene( “main” ) kind of worked out of everything, but it would reset “main”, which I do not want. Also it only worked once.

I’m using Version: 3.0.0 Build: 2018.3326

Check out the documentationclosely.

You need:

  1. scene:addEventListener( “hide”, scene ) in the overlay scene.
  2. a scene:hide(event) function in the overlay scene
  3. a scene:returnToGame function in the game scene

When hideOverlay() is called, the scene:hide fucntion is called.  In there you call event.parent:returnToGame()

In the code you posted, I do not see a scene:hide event listener or a scene:hide() function.

Thank you. I’ve tried that as well, but I’m getting a new error: “attempt to index local ‘parent’ (a nil value)”. I followed your instrustions and compared my code to a few sample codes, but I can’t get it. 

Can you post some code?

You need event.parent in the scene:hide(event) function

 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 -- Call the "resumeGame()" function in the parent scene parent:resumeGame() end end

In the main.lua I added

local scene = composer.newScene()

function scene:resumeGame()
end

Do you have a scene:addEventListener( “hide”, scene ) statement in the pause scene?

Yes, just before return scene

Solved my last problem. I’ve addad all the objects into the wrong group. I should’ve used sceneGroup. Thank you!