Pause Button

Any ideas on how to make it? I have a lot of time… I will try anything if it’s reasonable. Anything? Please? I couldn’t find any specific API document on it and I don’t think I could make my own pause button without help. [import]uid: 76200 topic_id: 16259 reply_id: 316259[/import]

Hey Noah,

How you would make a pause button really depends on what your app entails.

If you are using timers to keep track of time passed, scoring, etc, then you’d add a pause/cancel for them in the pause function.

If you are using physics, you would also stop physics within the pause function.

Then in your resume function you would resume/restart the timer(s) and physics.

Make sense?

Peach :slight_smile: [import]uid: 52491 topic_id: 16259 reply_id: 60504[/import]

Oh, yes, thanks! I don’t use timers because quite frankly I didn’t learn how to use them yet. I am using physics though and I get what you’re saying. So basically the pause/resume function could consist of the very simple ‘physics.start()’ and ‘physics.pause’ functions? Golly, I thought it would be much more complicated! Thank you Peach! [import]uid: 76200 topic_id: 16259 reply_id: 60506[/import]

@Peach In case of timers and transitions,must I store all timers and transitions and pause them manually? Isn’t there a easier way to cancel all timers and transitions? [import]uid: 64174 topic_id: 16259 reply_id: 60559[/import]

If you use a Runtime Listener to move your objects around you can add a pause boolean to your logic. When activated things then just stop moving. [import]uid: 10903 topic_id: 16259 reply_id: 60568[/import]

@Noah - If physics is the only thing “going on” in your app then yes, pausing and resuming physics by using [lua]physics.pause()[/lua] and [lua]physics.start()[/lua] :slight_smile:

@Satheesh - Yes you need to keep track of timers and transitions you create.

Peach :slight_smile: [import]uid: 52491 topic_id: 16259 reply_id: 60660[/import]

@Peach
I just found out that there is no transition.pause function :frowning:

I found some codes… The transitionManager class, BeebeGames class… But I hate to completely rewrite all my transition code.

Is there any easier way? [import]uid: 64174 topic_id: 16259 reply_id: 62295[/import]

Hey.

As an example, here is my basic pause function from the skateboarding app I’m currently working on.

function pause()  
  
 pause = true   
  
  
 pauseButton = display.newImage("pauseButton.png")  
 pauseButton.x = \_W - pauseButton.contentWidth / 2  
 pauseButton.y = \_H - pauseButton.contentHeight / 2  
 pauseButton.rotation = 90  
 pauseButton.alpha = .75  
  
  
 function pButton(event)   
 if event.phase == ended then  
 if pause == true then  
  
 local function pauseMenu()  
 local pMenu = display.newRoundedRect(0, 0, 250, 300, 10)  
 pMenu.x = \_W / 2  
 pMenu.y = \_H / 2  
 pMenu.strokeWidth = 5  
 pMenu:setFillColor(255,204,0)  
 pMenu:setStrokeColor(51,51,51)  
 pMenu.alpha = 0.75  
 pausegroup:insert(pMenu)  
  
 local pauseText = display.newText("Paused.", 20, 0, nil, 30)  
 pauseText.rotation = 90  
 pauseText.x = \_W / 2 + \_W / 5  
 pauseText.y = \_H / 2  
 pauseText:setTextColor(51,51,51)  
  
 local playButton = display.newImage("playButton.png")  
 playButton.x = \_W / 2 - \_W / 5  
 playButton.y = \_H / 2 - \_H / 5  
 pausegroup:insert(pauseButton)  
 playButton.rotation = 90  
  
 local function unPause()  
 pMenu:removeSelf()  
 pMenu = nil  
  
 pauseText:removeSelf()  
 pauseText = nil  
  
 playButton:removeSelf()  
 playButton = nil  
 print("UNPAUSED")  
  
 Timer1 = timer.performWithDelay(10,getScore, 0)  
 physics.start()  
 end  
  
 playButton:addEventListener ("tap", unPause)  
  
 end  
  
 pauseMenu()  
 timer.cancel(Timer1)   
 physics:pause()  
 print("PAUSED")  
  
 end  
  
 end  
  
 end  
 pauseButton:addEventListener ("tap", pButton)  
 end  
  
pButton()  

It’s not perfect, but it does the job. Hope it helps. [import]uid: 67933 topic_id: 16259 reply_id: 62374[/import]

Satheesh, transition manager class is good, I expect Beebe’s is too. (I haven’t used it for that but he’s a very smart guy :))

Rewriting small parts of code for the ability to pause transitions - up to you if you want to do it or not - honestly the code people have provided to use is great and very useful, imho.

Peach :slight_smile: [import]uid: 52491 topic_id: 16259 reply_id: 62444[/import]

could you set up two groups of objects AND then pause just one of the groups ?
so you got one object frozen and the other keeps moving ?

I realise that you could possibly “freeze” the object by making it “static”.
but then I want to release it back into being “dynamic”.

Does this sound right ?
[import]uid: 11094 topic_id: 16259 reply_id: 62791[/import]

@spider && Peach Thanks :slight_smile:

@Troynall
Even if I make my object static, its transitions do not pause. [import]uid: 64174 topic_id: 16259 reply_id: 62807[/import]

@Satheesh

yes unfortunately :frowning: So here is what I did. when the button was pressed, I set the objects transition.to alpha=0, this will make it invisible. I then captured the Y axis coordinate. set the object to nil. and then created a new object at the Y axis from above.

i know it sounds like a hack, but its straight forward and does what is expected. [import]uid: 11094 topic_id: 16259 reply_id: 63061[/import]