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]