Considering the following example code:
[lua] – print to console when second image is pressed
function dosomethingelse( event )
print(“clicked2”)
end
– cover screen with blank rectangle and a second image when first image is clicked
function dosomething( event )
print(“clicked1”) – also, print to console when first image is pressed
local rectangle = display.newRect(0,0,display.contentWidth,display.contentHeight)
local img2 = display.newImageRect(“img2.png”,64,64)
rectangle:setFillColor(0)
img2.x = 125
img2.y = 200 – put image 2 in a different spot that doesn’t overlap image 1
img2:addEventListener(“tap”,dosomethingelse)
end
local img1 = display.newImageRect(“img1.png”,64,64)
img.x = 100
img.y = 100
img1:addEventListener(“tap”,dosomething)[/lua]
With the above code, when you click the first image, it’ll show a black overlay with a new image in a different location. Now, if you click the location of the first image, again (even though it can’t be seen), it will still print to the console “clicked1”. Is there an easy way to remove this behaviour without using removeEventListener/addEventListener on every single item covered by the black overlay?
In other words, is there a way for the black overlay to “catch” all the clicks and nullify them if they are for a layer that’s below the overlay?
Another example, for clarity: If you make a game with a small inventory View that pops up, you don’t want to click on any enemies or something that may be hidden by the inventory popup. Is there a way to have clicks only interact with the inventory when clicking within the inventory view, but still able to interact with the HUD or environment when clicking outside the inventory view?
TIA,
Neil [import]uid: 200441 topic_id: 33537 reply_id: 333537[/import]
