Block touches with a rectangle

I used to use a different engine to make apps in the past and to block all touches I just put up an invisible rectangle. I’m making a game with many touchable objects and I simply want a popup that asks the player something and so it has yes and no buttons to click.

While this is up I wanted to put a simple invisible rectangle to disable all the other touchable objects. Not sure how to do that. All I found was ways to individually disable event listeners.

hi,

https://docs.coronalabs.com/api/type/DisplayObject/isHitTestable.html

:wink:

local r=myRectangle r.isHitTestable=true local fBlock=function() return true end r:addEventListener("tap",fBlock) r:addEventListener("touch",fBlock)

Thanks. Actually I messed around in the meantime and found my own way of doing it but your way looks good too. This was my way and this is the whole code:

 shield = widget.newButton({ x = display.contentCenterX, y = display.contentCenterY, onPress = function() return false end, width = display.actualContentWidth, height = display.actualContentHeight, fillColor = {default = {1,1,1,0.01}} })

Then I just set it to visible or invisible as I need it. Seems to work fine, not sure if there are any issues I’m overlooking though.

hi,

https://docs.coronalabs.com/api/type/DisplayObject/isHitTestable.html

:wink:

local r=myRectangle r.isHitTestable=true local fBlock=function() return true end r:addEventListener("tap",fBlock) r:addEventListener("touch",fBlock)

Thanks. Actually I messed around in the meantime and found my own way of doing it but your way looks good too. This was my way and this is the whole code:

 shield = widget.newButton({ x = display.contentCenterX, y = display.contentCenterY, onPress = function() return false end, width = display.actualContentWidth, height = display.actualContentHeight, fillColor = {default = {1,1,1,0.01}} })

Then I just set it to visible or invisible as I need it. Seems to work fine, not sure if there are any issues I’m overlooking though.