在Corona SDK中,当对象的alpha为0时获取触摸事件

如果我想要一个看不见的框,例如,如果它的 alpha 值为 0,我该如何获得触摸事件?还是有其他方法可以做到看不见的框。

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

它从未打印出 x 和 y,但是如果我不将 alpha 值设置为 0,则可以正常工作。

点赞
用户269870
用户269870

你需要在你的代码中添加这一行:

button.isHitTestable = true

来源:http://docs.coronalabs.com/api/type/DisplayObject/isHitTestable.html

2013-01-04 13:06:30
用户2656328
用户2656328

需要注意的是,如果父级组中有一个不可见(不考虑 isHittestable),则不会触发目标的回调。此外,设置母组的 isHittestable 也不会改变这一点。

2013-08-16 14:37:48