addEventListener:只有一个对象达到了结束阶段。

我有一个关于addEventListener “touch” 的问题。当两个或更多的对象位于附近并使用一个“touch”激活时,只有一个对象会接触到ended阶段。

我尝试了什么:

function theBall(event)
    local ball = event.target.id.id

    if event.phase == "began" then
        print("began")
        display.getCurrentStage():setFocus(event.target)
    end

    if event.phase == "ended" or event.phase == "cancelled" then
        print("ended")
        display.getCurrentStage():setFocus(nil)
    end

end

invisibleBall [ball]:addEventListener(“触摸”,theBall)

在模拟器输出中:

began
began
began
ended
点赞
用户1870706
用户1870706

如果不将一个:

return true

放在函数末尾,事件将会传递到其下方的任何对象。这是按设计来的。只需在最后一个结束前加上 return true,你的问题就可以得到解决。

2013-10-28 00:21:35