当 Corona SDK 中的功能触摸为 运行 时停止或取消功能触摸
stop or cancel function touch when the function touch is running in Corona SDK
触摸功能为运行时,有什么方法可以取消或停止触摸功能?
我在使用拖放功能时挂起,当单击对象并按住它直到计时器为 0 出现弹出对话框并且我挂起所有按钮,例如后退按钮不起作用,
问题解决:
您必须删除该对象才能停止该功能
使用 object:removeSelf()
感谢大家的帮助:)
抱歉耽搁了。我注意到您没有清除正在拖动的对象上的焦点。您必须先清除之前触摸侦听器的焦点,以便代码识别新的触摸,即使您删除了事件侦听器焦点仍然存在:
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
触摸功能为运行时,有什么方法可以取消或停止触摸功能? 我在使用拖放功能时挂起,当单击对象并按住它直到计时器为 0 出现弹出对话框并且我挂起所有按钮,例如后退按钮不起作用,
问题解决: 您必须删除该对象才能停止该功能 使用 object:removeSelf()
感谢大家的帮助:)
抱歉耽搁了。我注意到您没有清除正在拖动的对象上的焦点。您必须先清除之前触摸侦听器的焦点,以便代码识别新的触摸,即使您删除了事件侦听器焦点仍然存在:
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