Lua 在场景启动时延迟enterFrame函数

Lua 在场景启动时延迟enterFrame函数,lua,coronasdk,Lua,Coronasdk,我的游戏中有多个场景,在其中一个场景中,一个物理球后面跟着一组称为“游戏”的对象移动所有其他对象 local function loop(event) local targetx = 600 -ball.x if targetx>2550 then targetx = 2550 elseif targetx < display.contentWidth - 1451 then targetx = display.conte

我的游戏中有多个场景,在其中一个场景中,一个物理球后面跟着一组称为“游戏”的对象移动所有其他对象

local function loop(event)

    local targetx = 600 -ball.x

    if targetx>2550 then
        targetx = 2550
    elseif targetx < display.contentWidth - 1451 then 
        targetx = display.contentWidth-1451
    end
    game.x = game.x + ((targetx - game.x) *0.2)
end

Runtime:addEventListener("enterFrame", loop)
这可能无关紧要,因为我所需要的只是该功能在进入场景后1秒内才发生。我该怎么做呢?

看一看。这是电晕计时器。带延迟的性能看看。这是电晕计时器。使用延迟执行以下操作:

local function loop(event)
   ...
   ...
end

local function triggerListener()
  Runtime:addEventListener("enterFrame", loop)
end
timer.performWithDaelay(1000,triggerListener,1) -- Params: time in mS,function,loop
继续编码

像这样做:

local function loop(event)
   ...
   ...
end

local function triggerListener()
  Runtime:addEventListener("enterFrame", loop)
end
timer.performWithDaelay(1000,triggerListener,1) -- Params: time in mS,function,loop
继续编码