Game is restarted by pressing home button (iOS)

Hey, how can I do my game pause when the iOS user close my game (by pressing at the home button)?

When user do it, and then return to the game, the application is restarted, it does not continue at the same point when the user pressed the Home button.

I didn’t see any event or method that can handle it…

Does anyone know?

Thanks for attention [import]uid: 94630 topic_id: 19840 reply_id: 319840[/import]

Hey there,

You need to put this line in your build.settings file;

[lua]UIApplicationExitsOnSuspend = false[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 19840 reply_id: 76997[/import]

So if you do that, the app stays in memory?

Useful, but greedy: If so, when does it actually exit then? [import]uid: 108660 topic_id: 19840 reply_id: 77010[/import]

You newer know when - it is handled by iOS :slight_smile:

Joakim [import]uid: 81188 topic_id: 19840 reply_id: 77023[/import]

Thanks, works perfectly!!!

Thanks all for the help [import]uid: 94630 topic_id: 19840 reply_id: 77115[/import]

Jeff - the code lets the app be properly minimized without restarting, it exits when the user quits by holding down the icon then pressing the red close button in the corner, as with all iOS applications.

Edson - not a problem, happy to help.

Peach :slight_smile: [import]uid: 52491 topic_id: 19840 reply_id: 77207[/import]

>>it exits when the user quits by holding down the icon then pressing the red close button in the corner<<

Doesn’t that delete the app completely?
Pretty radical way to stop it from running. :slight_smile:

Still, thanks for the setting tip. I’ll experiment a bit [import]uid: 108660 topic_id: 19840 reply_id: 77222[/import]

Not from the multitasking bar, no - it simply closes the app.

On iOS the user double presses the home button which opens the dock/multitasking bar/whatever you want to call it; from there holding down for a moment will bring up an icon to close the apps that are running which are all visible here.

Deleting an app is done from the normal home screen and involves a black “X”, not a red close button.

Nothing radical about it :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 19840 reply_id: 77257[/import]

Well, whaddya know?
So that’s what that’s for!
Every day you learn something new. :slight_smile:
Thanks Peach.

(I just tried it and found just about every app I ever ran sitting in that bar.) [import]uid: 108660 topic_id: 19840 reply_id: 77267[/import]

Wow, lol - I’m glad I could help you learn that, then - it’s pretty important to prevent lag from a million apps running at once!

Awesome :slight_smile:

Peach [import]uid: 52491 topic_id: 19840 reply_id: 77321[/import]

The double tap home button, no one seems to know about. I wish there was some time based clean up. Hmm, I guess we could write an “app for that”??

Haha.

ng [import]uid: 61600 topic_id: 19840 reply_id: 77648[/import]

Hey, How can I pause the game when the user press the Home Button?

Thanks [import]uid: 94630 topic_id: 19840 reply_id: 77760[/import]

Peach, thanks for information) I was also worried about suspension of app [import]uid: 16142 topic_id: 19840 reply_id: 77763[/import]

Edson, by setting [lua]UIApplicationExitsOnSuspend = false[/lua] the game will resume as it was when it was minimized, like a pause.

No worries Darkconsoles :slight_smile:

Peach :slight_smile: [import]uid: 52491 topic_id: 19840 reply_id: 77980[/import]

Ok then Peach =)

Thanks for the help… :slight_smile: [import]uid: 94630 topic_id: 19840 reply_id: 79118[/import]

@Peach, one thing that would be nice if it was possible to bring up the ingame menu to “pause mode” before the app is in sleep - so that the player gets some time to start play again - when he/she starts the app again. Did you follow me?

Joakim

[import]uid: 81188 topic_id: 19840 reply_id: 79680[/import]

I believe you could do this now - listen for a system event then call the pause menu, I believe that should show it fine when you resume. (It’s how a lot of people handle saving when the app is minimized/quit.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19840 reply_id: 79790[/import]

Ok, i was thinking of that approach - but, yes theres always a but :wink:

I am using storyboard for my game and in my main.lua is the function:

local function onSystemEvent( event )  
 if( event.type == "applicationExit" ) then   
 db:close()  
 end  
end  
Runtime:addEventListener( "system", onSystemEvent )  

Thats for a “soft” close of my db, I guess that I can use this place for bringing up the “in game” menu. But, yes one more but :wink: The function to bring up this menu is within my “Game Logic” module. So there are two things playing around here.

First, is the game running? If yes, then bring up the menu when the user exit (easy implementation).

Second, how the heck do I execute the function within my gameLogic.lua file, from main.lua?

One approach would maybe to add a new eventListener to gameLogic.lua - but it doesn’t feel correct to have two listener, listening to the same song :slight_smile:

Regards, Joakim

[import]uid: 81188 topic_id: 19840 reply_id: 79818[/import]

Hey jkrassman…

I managed to pause the game when the user closes the app this way:

local function onSystemEvent( event )  
 if event.type == "applicationSuspend" then  
 pauseGame()  
 end  
end  
  
Runtime:addEventListener ( "system", onSystemEvent )  

I hope that helped. [import]uid: 94630 topic_id: 19840 reply_id: 79855[/import]

@edson.faccio, that did the thing, and brings up the “in game” menu and pauses it :slight_smile:

One thing I don’t like now with my application, is that I am using storyboard. I have my system events in main.lua - but now I got one more in playLogic.lua. Bad or good?

Joakim [import]uid: 81188 topic_id: 19840 reply_id: 79861[/import]