Using Beebe class to pause timers

Hello, I am new to Corona. I was wondering how I can use Beebe class to pause my game.
This is my “level_1.lua” file.

module(..., package.seeall)  
  
function new ()  
 local super = require("\_level\_1")  
 local this = super:newlevel\_1()  
  
--------------------beebe game class--------------------  
  
game = require( "beebegames" )  
  
local resetTimeCounter = game.resetTimeCounter  
local getCountedTime = game.getCountedTime  
local performAfterDelay = game.performAfterDelay  
  
local pauseAllTimers = game.pauseAllTimers()  
local resumeAllTimers = game.resumeAllTimers()  
local cancelAllTimers = game.cancelAllTimers()  
  
--------------------physics--------------------  
  
-- Setup Physics  
local physics = require ("physics")  
physics.start()  
physics.setGravity (0,0)  
  
--------------------ball--------------------  
  
-- Load Ball  
local ball = require("ball")  
  
-- Movement Function  
local function movement()  
  
 -- Get X & Y Accelerometer Input From Remote  
 local xAcceleration = remote.xGravity  
 local yAcceleration = remote.yGravity  
  
 -- Convert Input To Force  
 local xForce = xAcceleration \* 55  
 local yForce = yAcceleration \* 55  
  
 -- Apple Force To Ball  
 ball.applyForceToBall( xForce , -yForce )  
  
end  
Runtime:addEventListener( "enterFrame", movement )  
  
--------------------level--------------------  
  
-- Load level  
local level = require("level")  
  
--------------------Sign--------------------  
  
 local ui = require("ui")  
 local pause\_button = ui.newButton{  
 defaultSrc = imagelookup.table["Sign\_2"], defaultX = imagelookup.table["Sign\_2Width"], defaultY = imagelookup.table["Sign\_2Height"],  
 overSrc = imagelookup.table["Signover\_2"], overX = imagelookup.table["Signover\_2Width"], overY = imagelookup.table["Signover\_2Height"],  
 }  
 pause\_button.x = 260  
 pause\_button.y = 436.5  
 pause\_button.isVisible = true  
  
 this:insert(pause\_button)  
 this.pause\_button = pause\_button  
 return this  
end  
  

As you can see…the only thing that I have to pause is my “ball”.
How can I use beebe class to make it so that when you touch my “pause_button” it pauses the timers (just the ball)?

Thanks in advanced…sorry I am new to all this!

ps As you can see, I am also using corona remote with my gravity.
[import]uid: 15281 topic_id: 7009 reply_id: 307009[/import]

I am pretty sure all you have to do is physics.stop()

that should stop all physics movements.

you may wish to make sure all directional information is saved for when you restart it so you can pick up where you left off at.

Good luck Larry [import]uid: 11860 topic_id: 7009 reply_id: 24576[/import]

Hey, thanks for the reply.
Sorry… I am very new to this. What would my button look like to do this (what is the full code)? [import]uid: 15281 topic_id: 7009 reply_id: 24806[/import]

This is what my button looks like right now.
So, what would I add to make it pause all timers?

[code] local pause_button = ui.newButton{
defaultSrc = imagelookup.table[“Sign_2”], defaultX = imagelookup.table[“Sign_2Width”], defaultY = imagelookup.table[“Sign_2Height”],
overSrc = imagelookup.table[“Signover_2”], overX = imagelookup.table[“Signover_2Width”], overY = imagelookup.table[“Signover_2Height”],
}
pause_button.x = 260
pause_button.y = 436.5
pause_button.isVisible = true

this:insert(pause_button)
this.pause_button = pause_button
[/code]

Thanks again! [import]uid: 15281 topic_id: 7009 reply_id: 25230[/import]

Anyone know?

Thanks. [import]uid: 15281 topic_id: 7009 reply_id: 25770[/import]

Note - no brackets on local versions of beebegames stuff i.e.

local pauseAllTimers = game.pauseAllTimers  
local resumeAllTimers = game.resumeAllTimers  
local cancelAllTimers = game.cancelAllTimers  

Then try this:-

  
paused = false -- paused flag  
  
local onPauseTouch = function( event )  
  
 if event.phase == "release" then  
  
 if not paused then  
  
 print("Pausing")  
 pauseAllTimers()  
  
 else  
  
 print("Resuming")  
 resumeAllTimers()  
  
 end  
  
 paused = not paused -- flip paused flag  
  
 end  
  
end  
local pause\_button = ui.newButton {  
  
 defaultSrc = imagelookup.table["Sign\_2"],  
 defaultX = imagelookup.table["Sign\_2Width"],  
 defaultY = imagelookup.table["Sign\_2Height"],  
 overSrc = imagelookup.table["Signover\_2"],  
 overX = imagelookup.table["Signover\_2Width"],  
 overY = imagelookup.table["Signover\_2Height"],  
 onEvent = onPauseTouch, -- ADD THIS  
  
 }  
  
 pause\_button.x = 260  
 pause\_button.y = 436.5  
 pause\_button.isVisible = true  
  
 this:insert(pause\_button)  
 this.pause\_button = pause\_button  
  

[import]uid: 8366 topic_id: 7009 reply_id: 25871[/import]

Hey,

Thanks a lot for the reply/code.
I tried your code… it worked (when you pressed the button, the terminal said: paused, and when you pressed it again it said: resumed). So, it works. The only problem is… it does not pause my ball.
Is it because I get my ball like this?:

local ball = require("ball")  

Thanks

– [import]uid: 15281 topic_id: 7009 reply_id: 26030[/import]

As the ball is controlled by the physics engine you need to pause and resume that too…

[code]
paused = false – paused flag

local onPauseTouch = function( event )

if event.phase == “release” then

if not paused then

print(“Pausing”)
physics.pause() – PAUSE PHYSICS ENGINE
pauseAllTimers()

else

print(“Resuming”)
physics.start() – RESTART PHYSICS ENGINE
resumeAllTimers()

end

paused = not paused – flip paused flag

end

end
[/code] [import]uid: 8366 topic_id: 7009 reply_id: 26083[/import]

Thank you so much!!
This worked great!

I just had a few of questions: can I have my “pause button” open a new scene? I understand how to make this button just a pause button (not resume), you just remove the “else” part. So, in this way… I could also make a button that just “resumed” right?

So, I will make this button just pause, but when you press it (pause), I want it to open a new scene (this scene will have a resume button, but how can I kill this scene once resumed?). Is a new “scene/file” the right way to make a “pause menu”?

Thanks so much for your help!

PS is this were I would open a new “scene/file”?

 onEvent = onPauseTouch, -- ADD THIS

You could change scene etc in the onPauseTouch function.

If that’s what you want to do I would recommend using the Director Class:-

http://developer.anscamobile.com/code/director-class-10 [import]uid: 8366 topic_id: 7009 reply_id: 26261[/import]

Hey, if I change the scene in the “onPauseTouch” function, will it leave my “game scene” going behind it? (so that when you press resume it goes back to the “game” were it left off).
If so, (I have used director class a little in the past) what exactly would my bit of code look like to change my scene with director (if its in my director local group and I want to use “moveFromRight”)?

Thanks

– [import]uid: 15281 topic_id: 7009 reply_id: 26307[/import]

Hey, does anyone know?
What would code would I add after onEvent = onPauseTouch, to have it open a new scene with director? [import]uid: 15281 topic_id: 7009 reply_id: 26691[/import]

Maybe something like this:-

main.lua

director = require "director"  
  
local ui = require("ui")  
  
display.setStatusBar( display.HiddenStatusBar )  
  
local mainGroup = display.newGroup()  
  
mainGroup:insert(director.directorView)  
  
director:changeScene("runningScene")  

runningScene.lua

module(..., package.seeall)  
  
local localGroup = display.newGroup()  
  
paused = false -- paused flag  
   
local onPauseTouch = function( event )  
  
 if event.phase == "release" then  
   
 if not paused then  
  
 director:changeScene("pausedScene", "moveFromRight")  
   
 end  
  
 paused = not paused -- flip paused flag  
   
 end  
  
end  
  
function new()  
  
 -- Restart Timers and physics etc HERE (IF Stopped)  
  
 local label = display.newText("Running", 0, 0, "helvetica", 40)  
 label.x = display.contentWidth / 2  
 label:setTextColor(255, 0, 0)  
  
 pauseButton = ui.newButton {  
  
 default = "buttonSmall.png",  
 over = "buttonSmall\_Over.png",  
 onEvent = onPauseTouch,  
 text = "Pause",  
 emboss = true,  
 textColor = { 0, 0, 0, 255 }  
  
 }  
  
 pauseButton.x = display.contentCenterX  
 pauseButton.y = display.contentCenterY  
  
 localGroup:insert(pauseButton)  
 localGroup:insert(label)  
  
 return localGroup  
  
end  

pausedScene.lua

[code]
module(…, package.seeall)

local localGroup = display.newGroup()

local onResumeTouch = function( event )

if event.phase == “release” then

director:changeScene(“runningScene”, “moveFromLeft”)

end

paused = not paused – flip paused flag

end

function new()

– Pause Timers and stop physics etc HERE

local label = display.newText(“Paused”, 0, 0, “helvetica”, 40)
label.x = display.contentWidth / 2
label:setTextColor(0, 255, 255)

local resumeButton = ui.newButton {

default = “buttonSmall.png”,
over = “buttonSmall_Over.png”,
onEvent = onResumeTouch,
text = “Resume”,
emboss = true,
textColor = { 0, 0, 0, 255 }

}

resumeButton.x = display.contentCenterX
resumeButton.y = display.contentCenterY

localGroup:insert(resumeButton)
localGroup:insert(label)

return localGroup

end
[/code] [import]uid: 8366 topic_id: 7009 reply_id: 26729[/import]