Help with pausing Spawn Objects

Hi, i was wondering if there was a way to implement a pause function into this code so if someone press’s the button it will stop spawning these objects in this code:

local function trackCircles(obj)  
 obj:removeSelf();  
end  
  
local function spawnCircle()   
 local Circle = display.newCircle( 10, -100, 30 )  
 Circle:setReferencePoint(display.TopReferencePoint);  
 Circle.name = "snow"  
 physics.addBody(Circle, "dynamic")   
  
 function Circle:touch(e)  
 if(e.phase == "ended") then  
 trackCircles(obj);  
 end  
  
 return true;  
  
 end  
  
 Circle:addEventListener("touch", Circle)  
end  
  
tmr = timer.performWithDelay(500, spawnCircle, 20000);  

Thanks. [import]uid: 69054 topic_id: 18781 reply_id: 318781[/import]

kill the timer :slight_smile:

c [import]uid: 24 topic_id: 18781 reply_id: 72300[/import]

Yes good idea, i didnt think of that lol [import]uid: 69054 topic_id: 18781 reply_id: 72302[/import]

But what if i wanted to pause it then start it up again? [import]uid: 69054 topic_id: 18781 reply_id: 72303[/import]

restart timer :slight_smile:

c [import]uid: 24 topic_id: 18781 reply_id: 72304[/import]

i think you are over-engineering it :wink:
if timer is stopped
start timer
if timer is on and clicked on button
kill timer.

c
[import]uid: 24 topic_id: 18781 reply_id: 72305[/import]

Oh my bad haha. [import]uid: 69054 topic_id: 18781 reply_id: 72306[/import]

Take a look at this library :
Pausable timers and transitions with speed adjustment

Actually when you want to pause a timer, you have to kill it, when you resume the game, you have to create a new timer. there have no other options for this moment at least. [import]uid: 74676 topic_id: 18781 reply_id: 72311[/import]

Hey guys,

You actually CAN pause a timer if you’re a subscriber with access to the latest daily builds. There’s timer.pause() and timer.resume().

Peach :slight_smile: [import]uid: 52491 topic_id: 18781 reply_id: 72350[/import]

Oops , didn’t realise that have been added … :stuck_out_tongue: [import]uid: 74676 topic_id: 18781 reply_id: 72354[/import]