Corona SDK - 如何实现对象取消触摸

我正在使用 Corona SDK 制作游戏,我需要显示一些球。我已经为所有球对象实现了 TouchListener enter image description here

代码如下

local function ballTouchEvent(e)

    local touchedBall = e.target
    local phase = e.phase

    if phase == "began" then

        log("触摸开始")

    elseif phase == "moved" then

         log("移动中")

    elseif phase == "ended" or phase == "cancelled" then

        log("触摸结束")

    end

    return true
end

ball:addEventListener("touch",ballTouchEvent)

我想在用户触摸任何球并将其触摸移动到白色背景(没有球的地方)时实现一些功能。有人可以指导我如何实现吗?先感谢了

点赞
用户1046966
用户1046966

你可以添加一个组,然后在组的 end touch 调用中处理触摸监听器和完成你的工作。

请访问以下连接

Touch事件检测问题

2016-02-10 12:32:15
用户88888888
用户88888888

实现一个 React 按钮并实现点击监听器到该 React 按钮上。当用户离开白色空间时,将调用 React 监听器的结束阶段,您可以在其中放置您想要执行的实现。

function scene:create( event )
    sceneGroup = self.view
    local rect = display.newRect(centerX, centerY, constants.screenWidth, constants.screenHeight)
    -- rect:setFillColor( 0.0 )
    rect.name = "background"
    rect:addEventListener("touch",backTouchEvent)
    sceneGroup:insert( rect )
end
2016-03-11 05:42:54