Pause Mobile Apps When They Aren't Focused

Please make sure to follow the forum’s rules before posting.
:cross_mark: Posts that do not follow the rules will be ignored, closed and archived.

Hello,

I’ve made a couple forum posts already on issues I have with the one-click mobile exports, such as how they don’t conform to the screen’s aspect ratio or honor the landscape set in the properties panel on iOS (Shameless plug), so I’m sorry if another post like this is redundant.

However, in those posts, some others and I came to the conclusion that these issues are more likely to be attributed to bugs than anything else. As for a new quality of life feature I would like to see from mobile exports, I think making it so whenever the app is not in focus (when it’s running in the background, when the app switcher is open, when the control center is open, etc.), would be a good feature to have in one-click packaging for mobile devices. If nothing else, have it be something in the properties panel that could be toggled on and off.

Why do I want this feature?

I’ve been doing some research on how other mobile games function, and I’ve noticed that virtually all of them automatically freeze when the game is no longer what is being immediately focused on, and generally speaking, I think that’s a good feature for a lot of mobile games to have because given the nature of phones, it is not uncommon that while somebody is playing, something, usually a notification, will briefly prompt them to exit the app or quickly switch to another one.

If the game is still running in the background while all this is going on, it could leave the player open to getting hit by obstacles that they do not know are there, and could seriously set their progress back

I also found a community-made extension that shows something like this is plausible. It automatically pauses the game whenever it is not being focused on when it is being played on desktop.

Here is the code for PauseFocusLost by Telstarboy:

var sound_manager = runtimeScene.getGame().getSoundManager();

var volumen = sound_manager.getGlobalVolume();

window.addEventListener(‘focus’, function (event) {

sound_manager.setGlobalVolume(volumen);

runtimeScene.getGame().pause(false);

});

window.addEventListener(‘blur’, function (event) {

sound_manager.setGlobalVolume(0);

runtimeScene.getGame().pause(true);

});

I understand that the way GDevelop exports games to desktop and to iOS or Android is not one-to-one, but given that a feature like this works on desktop, I do feel there is at least a precedent for GDevelop to support this on mobile devices.

At the end of the day, I definitely feel like this would make mobile games exported with one-click packaging tools feel more polished and tailored to mobile devices in the long run.

Thanks for reading!

Didn’t realise this wasn’t already a thing, +1. Definitely would make for a welcome addition!