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

Mic*_*ael 2 events lua alpha coronasdk

例如,如果我想要一个隐形框,如果它的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
Run Code Online (Sandbox Code Playgroud)

它永远不会打印出x和y,但是如果我没有将alpha设置为0,那么它可以正常工作.

spe*_*der 9

您需要将此行添加到您的代码中:

button.isHitTestable = true
Run Code Online (Sandbox Code Playgroud)

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