lua - Timer called twice in scene Corona SDK -
i have timer in code spawns objects every 1 seconds. when object collides "deathobj" scene changes scene2 scene1. when scene1 return scene2 timer called twice, if retry called 4 times etc... how can call timer once?
function scene:show( event ) local scenegroup = self.view local phase = event.phase if ( phase == "will" ) elseif ( phase == "did" ) local function spawn() --things spawn object end end local function deathobjcollision(self, event) if (event.phase == "began" ) 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
try pause or cancel timer when change scene 2 scene 1.
Comments
Post a Comment