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 )
精彩评论