Pausing game when turning off

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Pombo
Prole
Posts: 5
Joined: Sun Jul 17, 2022 1:16 am

Pausing game when turning off

Post by Pombo »

Is there a way of pausing the game automatically whenever the player turns off the phone or when they press the home button?
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Pausing game when turning off

Post by dusoft »

Does not Android pause apps automatically when putting them in the background (and background permission is not given)?
RNavega
Party member
Posts: 354
Joined: Sun Aug 16, 2020 1:28 pm

Re: Pausing game when turning off

Post by RNavega »

I think it's this handler here, but do test if doing those things you mentioned will trigger a focus change:
https://love2d.org/wiki/love.focus
User avatar
marclurr
Party member
Posts: 145
Joined: Fri Apr 22, 2022 9:25 am

Re: Pausing game when turning off

Post by marclurr »

I'd assumed what dusoft said was true, but I just checked a random prototype I have on my Android phone and pressing the home button doesn't seem to pause the main loop. The callback RNavega mentioned should let you implement that yourself easily though.
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Pausing game when turning off

Post by dusoft »

Good tip for anybody developing for Android (and possibly desktop as well - tabbing out of window pauses a game, tabbing back starts it again).
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: Pausing game when turning off

Post by darkfrei »

Make dt small again!
If dt > 1/20 then dt = 1/20 end
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
RNavega
Party member
Posts: 354
Joined: Sun Aug 16, 2020 1:28 pm

Re: Pausing game when turning off

Post by RNavega »

darkfrei wrote: Mon Oct 28, 2024 9:45 am Make dt small again!
If dt > 1/20 then dt = 1/20 end
Interesting. You're saying that, if the game app happens to get suspended (actually paused) by the device, then the main loop (love.run) won't run, and so time will accumulate and when the game gets unpaused dt will have some huge delta time, say 10 minutes (600 seconds) or whatever time that the game was left paused for, which might mess something up in your game.
So you put a top cap on how big dt can be (1/20s = 0.050s = 50ms) to avoid that.
User avatar
marclurr
Party member
Posts: 145
Joined: Fri Apr 22, 2022 9:25 am

Re: Pausing game when turning off

Post by marclurr »

I'm almost certain that didn't happen in my quick test. Things were collected and menu screens were opened while the app was in the background. If the delta was huge and it just caught up my game would have glitched badly as it doesn't handle large deltas.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest