0

我正在创建一个对象,我希望它在我对其应用触摸事件时使其可拖动,如果用户触摸该对象超过 5 秒,则该对象不能作为可拖动对象工作,但我必须调用其他一些函数,之后我想清除计数器,以便在下次触摸后重新初始化......如何在电晕中实现它我正在尝试使用 Timer = os.time() 但无法获得完美的结果。请提出任何想法...谢谢

local function callfunc( event )
    local phase = event.phase
      if "began" == phase then
         Timer = os.time()
      if Timer>5 then
         func1()
        else
         func2()
    end
end

Runtime:addEventListener("touch",callfunc)
4

2 回答 2

0

i'm assuming that you cannot get what you achieve because you did not remove the listener when going to another function see my code as a reference:

local function func1()

--set the object as draggable 

end

local function func2()
--remove the listener of the func1() and set another listener here
--call other function here

end

local function callfunc( event )
    local phase = event.phase
      if "began" == phase then
         Timer = os.time()
      if Timer>5 then
         func1()
        else
         func2()
    end
end

Runtime:addEventListener("touch",callfunc)

you can post another snippet of your code where the problem occurs if the idea above does't work since i only assume the problem that you have encountered. its hard to point out where the problem occur if there is only a snippet of code.

于 2013-08-18T12:54:39.110 回答
0

触摸事件传递的事件表有事件发生的时间。我会在开始阶段存储 event.time。然后,当您进入第一个移动阶段时,如果时间超过 5 秒,则以一种方式行事,否则以另一种方式行事。

于 2013-08-18T21:50:49.973 回答