在Corona SDK中运行功能触摸时停止或取消功能触摸

时间:2015-06-27 06:37:02

标签: corona ontouchevent

触摸功能运行时取消或停止触控功能的任何方法? 我有一个使用拖放功能,当点击对象并按住它直到计时器为0出现弹出对话框,我挂了所有按钮,如后退按钮不起作用,

问题解决: 您必须删除该对象才能停止该功能 use object:removeSelf()

感谢每个男生的帮助:)

1 个答案:

答案 0 :(得分:0)

抱歉延误。我注意到你没有清除你正在拖动的物体上的焦点。您必须首先清除以前的触摸侦听器的焦点,以便代码识别新的触摸,即使您移除了事件监听器,焦点仍然存在:

local objectTouched --This is to get the event.target.id that you will use later assuming that your event.target.id is a number

local function dragAndDrop (e)

    target = {}
    distanceBetweeen = {}

    objectTouched = event.target.id

    for i = 1, #checkPoint do 
        target[i] = checkPoint[i]
    end


        if e.phase == "began" then

            --YOUR CODE

        elseif e.phase == "moved" then

            --YOUR CODE

        elseif e.phase == "ended" then

            --YOUR CODE

        elseif e.condition == "forceCancelled" then

             -- ADD THIS CONDITION SO THAT THE FUNCTION WILL REMOVE -- THE FOCUSED OBJECT FIRST

            display.getCurrentStage():setFocus(nil)

        end

end


function timeoutGame()
    --BEFORE YOU REMOVE THE EVENT LISTENER CALL THIS FIRST
    ilusi[objectTouched]:dispatchEvent({name = "touch", target = ilusi[objectouched], condition = "forceCancelled"})
    timeoutGroup.alpha = 1 
    timeoutGroup:toFront()
    btnPause:removeEventListener("tap", pauseGame)
    btnReload:removeEventListener("tap", goTo)

    for i=1, #jawabanPasti do
        ilusi[i]:removeEventListener ("touch",dragAndDrop)
    end   


end