How to disable hidden buttons?

Let’s say

-I have a button that listens to a “tap” event, and directs to a function that does something.

-I put an ImageRact that covers the button. One layer up.

When I click on the cover image just above the area the buttons lies behind , the event function STILL executes.

How do I avoid this?

example:

local function hidebg() display.remove(logo3) logo3=nil end local logo2= display.newImage("logo.png") logo2.x=display.contentCenterX logo2.y=280 logo2.width=200 logo2.height=74 logo2:addEventListener("tap", hidebg) local cover =display.newImageRect("NEW GAME A.png", 480,320) cover.x=display.contentCenterX/2 cover.y=display.contentCenterY/2

The hidebg() function is still executed although the “logo2” is covered by “cover” image.

I know I could make the button isVisible=false and solve the problem, but I have dozens of buttons in different groups in different layers, and I wonder how to do it in a smart way. Maybe somehow disable a whole group? I don’t know.

You can save all buttons in a table and run through it with a loop to disable and enable them all.

Or you create an invisible overlay that reacts to touch (or tap) but does nothing more then returning true.

[lua]

local overlay = display.newRect(0,0, display.contentWidth, display.contentHeight)

overlay.isVisible = false

over.isHitTestable =true

function overlay:touch()

   return true

end

overlay:addEventListener(“touch”)

[/lua]

I see three options here:

  1. I think it works if you just do

logo2.isVisible = false

  1. you can remove the listener on “logo2” when you display “cover”, and add it back again later on when you need it:

logo2:removeEventListener(“tap”, stopClicksOnLogo)

  1. or if you also add another listener to your variable “cover”, with a return true in it just to stop it from calling “logo2”. Something like:

local function stopClicksOnLogo(event)

    return true

end

cover:addEventListener(“tap”, stopClicksOnLogo)

You can save all buttons in a table and run through it with a loop to disable and enable them all.

Or you create an invisible overlay that reacts to touch (or tap) but does nothing more then returning true.

[lua]

local overlay = display.newRect(0,0, display.contentWidth, display.contentHeight)

overlay.isVisible = false

over.isHitTestable =true

function overlay:touch()

   return true

end

overlay:addEventListener(“touch”)

[/lua]

I see three options here:

  1. I think it works if you just do

logo2.isVisible = false

  1. you can remove the listener on “logo2” when you display “cover”, and add it back again later on when you need it:

logo2:removeEventListener(“tap”, stopClicksOnLogo)

  1. or if you also add another listener to your variable “cover”, with a return true in it just to stop it from calling “logo2”. Something like:

local function stopClicksOnLogo(event)

    return true

end

cover:addEventListener(“tap”, stopClicksOnLogo)