Can somebody point me to simple way to pause my game which works with director class?
I have simple physics and sprites in my game “scene”. I want to show pause button on top right corner , which when tapped, pauses the game (physics, sprites and transitions) and shows a popup window saying “Paused” and option to unpause.
I tried coding something simple like below, but it’s not very stable and my physics object don’t resume there original states.
The gameListeners() function is the function in the same file which adds or removes all the event listeners based on function parameter.
[lua]function pause()
gameListeners(‘remove’)
physics.stop()
local pauseScreen = display.newGroup()
localGroup:insert(pauseScreen)
local pauseWindow = display.newRect(pauseScreen, screenWidth*0.5-100, screenHeight*0.5-75, 200, 150 )
local msg = display.newText(pauseScreen, “Game Paused”, pauseWindow.x-30, pauseWindow.y-50, “Helvetica”, 20)
local resume = display.newText(pauseScreen, “Resume”, pauseWindow.x-30, pauseWindow.y+30, “Helvetica”, 20)
pauseWindow:setFillColor(0,0,0)
local function removePauseScreen()
pauseWindow:removeSelf()
msg:removeSelf()
resume:removeSelf()
pauseScreen:removeSelf()
end
local function resumeGame()
removePauseScreen()
physics.start()
gameListeners(‘add’)
end
resume:addEventListener(“tap”, resumeGame)
end[/lua] [import]uid: 48521 topic_id: 9400 reply_id: 309400[/import]