【发布时间】:2015-11-13 00:42:57
【问题描述】:
我的代码中有一个计时器,它每 1 秒生成一次对象。 当一个物体与“deathObj”碰撞时,场景会从场景 2 变为场景 1。 但是当我从场景1返回场景2时,计时器被调用两次,如果我重试将被调用4次等等...... 如何调用一次计时器?
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
elseif ( phase == "did" ) then
local function spawn()
--things for spawn the object
end
end
local function deathObjCollision(self, event)
if (event.phase == "began" ) then
composer.gotoScene("scene1")
end
end
deathObj = display.newRect(300,1900,1600,100)
physics.addBody(deathObj, "static", {density=1.0, friction=0.5, bounce=0.3})
deathObj.collision = deathObjCollision
deathObj:addEventListener( "collision", deathObj )
spawnTimer = timer.performWithDelay(1000, spawn, -1)
end
end
【问题讨论】:
标签: timer lua sdk coronasdk scene