开发者

How can I delay, or pause, a function in ansca's corona? (lua)

I can't find it documented anywhere :/

(question is the title)

found this but can't get it to work.

function onCollision( event )
   --code-- 
end

Runtime:addEventListener( "collision", listener )

 local f开发者_运维百科unction listener( event )
     timer.performWithDelay(
1000, onCollision )
end


Your issue is one of code order. function essentially sets the value for the given symbol. From the Lua manual:

The statement

 function f () body end

translates to

 f = function () body end

As such, listener is nil at the time you're passing it to addEventListener. Reorder, and it should work:

function onCollision( event )
   --code-- 
end

local function listener( event )
  timer.performWithDelay(1000, onCollision )
end

Runtime:addEventListener( "collision", listener )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜