Reputation: 455
If I wanted to have an invisible box, for example, how could I get touch events if it has an alpha of 0? Or is there another way to make an invisible box.
local function invisiblebuttontouch(event)
if event.phase == 'began' then
print (event.x..","..event.y)
end
end
button = display.newRect(1,1,300,300)
button:addEventListener("touch",invisiblebuttontouch)
button.alpha = 0
It never prints out the x and y, however if I don't set the alpha to 0, then it works fine.
Upvotes: 2
Views: 2612
Reputation: 595
it should be noted that no callback for a target will be fired if one of the parent groups are invisible disregarding isHittestable. Also setting isHittestable of the mother group won't change that.
Upvotes: 2
Reputation: 6296
You need to add this line to your code:
button.isHitTestable = true
Source: http://docs.coronalabs.com/api/type/DisplayObject/isHitTestable.html
Upvotes: 10