开发者

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

开发者 https://www.devze.com 2023-03-29 20:42 出处:网络
I can\'t find it documented anywhere :/ (question is the title) found this but can\'t get it to work. function onCollision( event )

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

精彩评论

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