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 に答える