I would also add that when you have a popup of some kind, it can be useful to put a full screen invisible rect behind it and have that return true for touches / taps, so that the user can touch outside the popup without accidentally triggering events behind the popup.
Or you could have the invisible rect close the popup if the user touches outside it’s bounds.
I always have the global function in main.lua so I can use it in multiple scenes:
function newTouchBlocker(visible)
function Block(e)
return true
end
local blocker = display.newRect(0, 0, display.contentWidth, display.contentHeight)
if not visible then
-- we don't need to see it so make it invisible
blocker.isVisible = false
else
--or you could always make it a semi-transparent color (e.g. for a pause screen)
block:setFillColor(0, 0, 0, 64)
end
-- we DO need to be able to touch it though
blocker.isHitTestable = true
--and we want to block both touches and taps
blocker:addEventListener("touch", touchBlocker)
blocker:addEventListener("tap", touchBlocker)
return blocker
end
Then just before my popup items are created I would do:
[code]
–param sets whether it is visible or not
local block = newTouchBlocker( true )
local myPopupStuff = display.new…
[/code] [import]uid: 84115 topic_id: 35528 reply_id: 141229[/import]