如何在自来水功能中对电晕进行连续动作

she*_*min 2 lua coronasdk

如何在水龙头功能中对电晕进行连续动作?我的意思是event.phase="began"直到它的动作重复直到它结束.

我的代码:

function upArrowtap(event)
  if (event.phase == "began") then
    if ( ball.y > 45 ) then
      transition.cancel(trans1)
      transition.cancel(trans2)
      --ball.y = ball.y-15
      start()
    end
  end
end

upArrow:addEventListener("touch", upArrowtap)
Run Code Online (Sandbox Code Playgroud)

希望你理解我的问题.

jho*_*ing 8

首先,使用事件监听器"触摸"而不是"点击".Tap事件侦听器仅在移除手指时响应,但触摸侦听器响应触摸的开始和结束.

其次,要重复一个事件,你需要使用enterFrame.因此,在触摸开始时设置一个enterFrame侦听器,并在触摸结束时删除enterFrame侦听器:

local function onEnterFrame(event)
  ball.y = ball.y + 2
end
local function onTouch(event)
  if (event.phase == "began") then
    Runtime:addEventListener("enterFrame", onEnterFrame)
  elseif (event.phase == "ended") then
    Runtime:removeEventListener("enterFrame", onEnterFrame)
  end
end
button:addEventListener("touch", onTouch)
Run Code Online (Sandbox Code Playgroud)

(我可能错了几个关键字,我只是输入了我的头脑)