[Resolved] Pausing and Game Over function problems

So bombs are falling from the top of the screen using math.random in my game. I have a pause function and a game over function. When you pause the game, everything is supposed to freeze. Everything freezes with the exception of the bombs. When I unpause the game, many bombs are stored and then they all fall at once. It seems like they just keep on piling up whenever I pause or finish up the game. What is the easiest way to freeze objects whenever the game is paused or the game over function is triggered?

Here is my createBomb code:

[lua]local function createBomb()
local bomb = display.newImageRect(“bomb.png”, 74 / 2, 100 / 2)
bomb.name = “bomb”
bomb.x = math.random(0 + bomb.width, display.contentWidth - bomb.width)
bomb.y = 0 - bomb.height
physics.addBody(bomb, “dynamic”, {isSensor = true})
localGroup:insert(bomb)

return bomb
end[lua]Here is my pause code:

[lua]local onPauseTouch = function(event)
print( “–> onPauseTouch 1: description” )
if event.phase == “release” and pauseBtn.isActive then

if gameIsActive then
print( “–> onPauseTouch 1: game Active” )

gameIsActive = false
physics.pause()

local function pauseGame()
timer.pause(timerInfo)
print(“timer has been paused”)
end
timer.performWithDelay(1, pauseGame)

–Shade
if not shade then
shade = display.newRect(0, 0, 570, 380)
shade:setFillColor(0, 0, 0, 255)
shade.x = 240; shade.y = 160
displayGroup:insert(shade)
end
shade.alpha = 0.5

–Show Menu Button
if pauseBG then
pauseBG.isVisible = true
pauseBG.isActive = true
pauseBG:toFront()
end

pauseBtn:toFront()

else
print( “–> onPauseTouch 1: game Not Active” )

if shade then
display.remove(shade)
shade = nil
end

if pauseBG then
pauseBG.isVisible = false
pauseBG.isActive = false
end

gameIsActive = true
physics.start()

local function resumeGame()
timer.resume(timerInfo)
print(“timer has been resumed”)
end
timer.performWithDelay(1, resumeGame)

end
end

return true
end[lua] [import]uid: 69494 topic_id: 29206 reply_id: 329206[/import]

hi i am new on corona but i make a pause function and i use physics.pause() like you and it works perfectly… i am using physics too and i simple do this:

[lua]function pauseGame (event)
if (event.phase ==“began”) then
pause:setFillColor(34,65,78)
end
if (event.phase == “ended”) then
–stop physics
physics.pause()
—pause the timer countdown
result = timer.pause(count_timer)
pause.isVisble = false;
menubtn.isVisible = true;
reset.isVisible = true;
continue.isVisible = true;
end
end[/lua]
pause:addEventListener( “touch”, pauseGame ) [import]uid: 138440 topic_id: 29206 reply_id: 117471[/import]

That’s similar to mine but the problem is that the bombs are piling up when everything else is frozen. When I resume the game, the bombs that were piled up all come down at the same time. Even after the restart function is triggered when the game restarts after it finishes. [import]uid: 69494 topic_id: 29206 reply_id: 117533[/import]

OOOO can you put your create bomb function… i mean when you called because maybe you still creating bombs when the physics are pause or something like… [import]uid: 138440 topic_id: 29206 reply_id: 117558[/import]

Hey neilw711

Is your spawning function for the bombs being called by a timer?

If yes, simply pause that timer.

Ex:
[lua] local spawnTmr = timer.performWithDelay(1000, createBomb, -1)

if spawnTmr ~= nil and gameIsActive == true then
timer.pause(spawnTmr)
else
timer.resume(spawnTmr)
end [import]uid: 40731 topic_id: 29206 reply_id: 117598[/import]

Wow, I can’t believe I left out the timer.performWithDelay lol. It’s under my createBomb function and I completely missed it. Thanks brian-nexus! I really appreciate the help! [import]uid: 69494 topic_id: 29206 reply_id: 117601[/import]