Hey all, I’m working on understanding the specifics of composer and overlays and there really aren’t many examples to help. I am able to get standard composer scenes to show and transition properly, but I’m having a little trouble with overlays. I am able to get the overlay to show, but am not sure how to properly setup the code in the overlay.lua file. It shows, but when I “hide” the overlay, the display objects in the overlay scene do not hide. How do I handle the screen group for my overlay.lua file? Code from parent and overlay is below:
Parent file:
local composer = require( “composer” )
local scene = composer.newScene()
function scene:create( event )
local sceneGroup = self.view
function ActionTouch(e)
local myButtons = e.target
local ID = myButtons.id
if e.phase == “ended” then
if ID==“Pause” then
print(“Showing Overlay”)
composer.showOverlay( “Overlay”, {isModal=true, effect=“slideDown”} )
end
end
end
btnText=display.newText( {text=“SHOW OVERLAY”, x=200, y=264, font=native.systemFontBold, fontSize=32, width=300, height=50, align=“center”} )
btnText:setFillColor( 0.7 )
btnText:addEventListener( “touch”, ActionTouch)
btnText.id=“Pause”
sceneGroup:insert( btnText )
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen).
elseif ( phase == “did” ) then
– Called when the scene is now on screen.
– Insert code here to make the scene come alive.
– Example: start timers, begin animation, play audio, etc.
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is on screen (but is about to go off screen).
– Insert code here to “pause” the scene.
– Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen.
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s view (“sceneGroup”).
– Insert code here to clean up the scene.
– Example: remove display objects, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
Overlay file:
local composer = require( “composer” )
local scene = composer.newScene()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
local parent = event.parent --reference to the parent scene object
end
– By some method (a “resume” button, for example), hide the overlay
–composer.hideOverlay( “fade”, 400 )
function ActionTouch(e)
local myButtons = e.target
local ID = myButtons.id
if e.phase == “ended” then
if ID==“Continue” then
composer.hideOverlay( “fade”, 400 )
end
end
end
btnContinueText=display.newText( {text=“OVERLAY---------------RESUME GAME”, x=500, y=564, font=native.systemFontBold, fontSize=42, width=500,align=“center”} )
btnContinueText:setFillColor( 0.7 )
btnContinueText:addEventListener( “touch”, ActionTouch)
btnContinueText.id=“Continue”
scene:addEventListener( “hide”, scene )
return scene