Page 1 of 1
Pausing game when turning off
Posted: Fri Oct 25, 2024 8:28 pm
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?
Re: Pausing game when turning off
Posted: Fri Oct 25, 2024 9:32 pm
by dusoft
Does not Android pause apps automatically when putting them in the background (and background permission is not given)?
Re: Pausing game when turning off
Posted: Fri Oct 25, 2024 11:59 pm
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
Re: Pausing game when turning off
Posted: Sat Oct 26, 2024 8:10 am
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.
Re: Pausing game when turning off
Posted: Sat Oct 26, 2024 12:07 pm
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).
Re: Pausing game when turning off
Posted: Mon Oct 28, 2024 9:45 am
by darkfrei
Make dt small again!
If dt > 1/20 then dt = 1/20 end
Re: Pausing game when turning off
Posted: Mon Oct 28, 2024 12:41 pm
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.
Re: Pausing game when turning off
Posted: Mon Oct 28, 2024 3:05 pm
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.