Hi Markus, you’re right on that! I did not realize that insert()ing into the scene view was needed for the overlay to work. Thanks for that. However, this does NOT fully solve the problem.
I updated the code with insert()s and a Hide Overlay button.
[lua]
— main.lua
local composer = require(‘composer’)
composer.gotoScene(‘scene1’)
— scene1.lua
local composer = require(‘composer’)
local scene = composer.newScene()
local widget = require(‘widget’)
function scene:create(event)
local bg = display.newRect(0, 0, 320, 480)
bg.anchorX, bg.anchorY = 0, 0
bg.fill = { 1, 0, 0 } – Red background
self.view:insert(bg)
local function onTap(event)
print('scene1 click detected: ', event.name, event.phase, event.x, event.y)
end
bg:addEventListener(‘tap’, onTap)
local function showOverlayClicked(event)
– isModal so events should not propagate to scene1
print(‘Show Overlay clicked’)
composer.showOverlay(‘scene2’, { isModal = true })
end
local showOverlayButton = widget.newButton({
x = 160,
y = 240,
label = ‘Show overlay’,
fontSize = 20,
shape = ‘roundedRect’,
width = 160,
height = 30,
fillColor = { default = {0, 1, 0}, over = {0, 0, 1} },
onRelease = showOverlayClicked
})
self.view:insert(showOverlayButton)
end
scene:addEventListener(‘create’, scene)
return scene
— scene2.lua
local composer = require(‘composer’)
local scene = composer.newScene()
local widget = require(‘widget’)
function scene:create(event)
print(‘in scene2’)
local bg = display.newRect(160, 120, 160, 240)
bg.fill = { 1, 1, 1 } – White background
self.view:insert(bg)
local function hideOverlayClicked(event)
print(‘Hide Overlay clicked’)
composer.hideOverlay()
end
local hideOverlayButton = widget.newButton({
x = 160,
y = 225,
label = ‘Hide overlay’,
fontSize = 20,
shape = ‘roundedRect’,
width = 160,
height = 30,
fillColor = { default = {0, 0, 0}, over = {0, 0, 1} },
onRelease = hideOverlayClicked
})
self.view:insert(hideOverlayButton)
end
scene:addEventListener(‘create’ , scene)
return scene
[/lua]
In this code, when the overlay is shown, nothing passes through to the scene underneath unless you click Hide Overlay. If you click Hide Overlay, you see printed:
10:09:19.644 Hide Overlay clicked
10:09:19.644 scene1 click detected: tap nil 227 236
Any idea on why? If I wrap composer.hideOverlay in a timer (of even 1 millisecond) the problem goes away.