Keep game running out of focus

Hello, I just noticed that if the browser window is not on focus the game stops or pauses, then when on focus again the game resumes.

How to enable the game to be continuously running even if the browser window is out of focus or minimized?

Thanks in advance. 

++++

As a rule, Corona apps are not designed to be run in the background. I would assume this applies to HTML5 builds as well, but I’m verifying with Engineering.

Rob

When an application is embedded in social networks, then there the payment and invitation windows stop the application - this is bad!

To avoid pauses, I edited coronaHtml5App.js in fbinstant_app.zip.

I removed “blur” callback like this. 

In the function “_emscripten_set_blur_callback”, 

function \_emscripten\_set\_blur\_callback(target,userData,useCapture,callbackfunc){JSEvents.registerFocusEventCallback(target,userData,useCapture,callbackfunc,12,"blur");return 0}

remove registerFocusEventCallback

function \_emscripten\_set\_blur\_callback(target,userData,useCapture,callbackfunc){return 0}

It works fine on Facebook instant games.

Would be great to have an options to disable this feature. Some games - are just idle =)

Hey guys,

@Rob

this is important.

I have a few games that should work while tab is not active.

And it is natural for browser games. =)

Would be great to have this feature on/off. (suspend on losing focus)

These sort of issues are bound to happen when an engine like Corona is clearly intended to be iOS/Android first and all other platforms are treated as simple extensions of these two platforms.

Apps weren’t generally expected to run on the background for iOS and Android. Of course, these days there are apps where running in the background is absolutely necessary and so it is supported by both platforms. Now, for HTML5 games, running in the background is pretty much the standard.

Same thing with confining mouse movement to application window. Since mobile device screens end where the app ends, there’s no need for such a feature for iOS and Android, but for HTML5, Windows, Mac and Linux, this is close to mandatory.

In order to be a truly multi platform SDK, Corona needs to account for the peculiarities and the needs of each specific platform that it supports.

I think - ‘suspend’ corona event coded on ‘lost focus’ html5 event. That is on purpose.

All I ask - is to add an option on/off it, or to remove/comment this part of code for now.
it works fine for win32 builds(losing focus dosent suspend app).

Same, as for ‘upscale’ issue. This is not something that happens by default - someone coded that stuff.

(And again - I’m beggin to comment/remove this part out, or fix it - this is a critical problem that prevents me from publishing my games on web portals)

@Rob have mentioned - that is something that he thinks is necessary or expected. Same as for upscale.

I’m still puzzled if I was convincing enough to turn ‘upscale’ feature to bug.

TL;DR: Nope. This is not a cross-platform problem. Just a feature that is not needed.

Upscale bug:

https://forums.coronalabs.com/topic/76868-graphics-and-fonts-blurry/

https://forums.coronalabs.com/topic/76818-weird-window-size-bug/

You seem to have misunderstood my entire point, @efgames.net.

Yes, that upscaling issue with blurred graphics and fonts is a bug that needs to be fixed. Now, if you know that “someone just wrote in some lines of code that can be commented out that will fix this bug”, then let them know what those lines are or handle it yourself and push an update to GitHub. I rather expect that the problem lies somewhere with Corona not properly recognising the HTML5 canvas size (or something along those lines), which leads to it failing to properly scale the assets.

Now, the thing is that many of these other problems exist purely because Corona is mobile first AND these issues do not really exist for mobile platforms and they haven’t been addressed (yet). A mouse cursor (or rather a player’s finger) cannot physically move outside of a mobile screen without a touch event ending. This is purely a desktop/web related issue. Same deal with apps running in the background. Apple and Google want apps to do as little as possible once they’ve been suspended, but the same does not apply to HTML5 apps.

If Corona wasn’t cross-platform, then these issues would not exist, which was my entire point. As new platforms are introduced, their peculiarities and what developers and users expect from apps running on said platforms need to be taken into account. However, these are rarely as simply as you make them out to be, because if they were, then someone would have already taken care of them.

A feature that isnt needed on one platform but is needed on another platform sounds like a platform issue to me

I always thought this was more because some browsers disable, or restrict, JavaScript when a tab loses focus? I.e. the Corona game pauses because the browser is restricting its capabilities rather than because of anything Coronalabs are in control of?

What do other SDKs do?

Hi, I literally just have this same problem today. On a web browser the “game” part that Corona is handling is just a part of the web page. Other parts of the web page might show high scores, or a chat window, some other aspect of the game, these will fall outside Corona.

I notice than when the user clicks away from the game (yet still on same webpage), the game pauses, I would very much like a way to turn this off… the game should carry on.

As another person mentioned, i can see from my debugging that the application is suspended.
 

Richard, I believe you might be thinking of “audio context” limitation – many browsers will not play sounds when the user has not explicitly clicked on a widget, this is to stop annoying ads playing… however this does not “pause” part of a page, so for example if you go to YouTube and start playing a video, the video does not stop playing because you leave a comment.

I can confirm that as hiramatsu above mentioned, i did unzip the .bin file, edited the .js file, re-zipped the .bin and replaced the original bin – and the game no longer pauses when it loses focus to another webpage element.

Of course I do not know if this breaks other things.

You know, the source code for Corona is open source. You are more than welcome to download it from GitHub, make this change, test it and issue a pull request back so we can incorporate it into the product for everyone to benefit.

https://github.com/coronalabs

Rob

That project is huge, I cloned the github… couldn’t even find the call.

Probably need to comment lines 620-624 of c++ file corona/platform/emscripten/Rtt_EmscriptenContext.cpp

But how would one even build & test this? AFAIK the processing of a corona lua project take place on your server.

There are instructions at the bottom of this page, though admittedly they’re pretty sparse.  :slight_smile: Combine them with the corresponding Mac or Windows page. (I still haven’t tried Emscripten builds myself.)

Commenting out those lines is a rather sledgehammer approach, since some might want the current behavior. A better approach would be to also incorporate a user setting here.

Ref articles like https://www.theverge.com/2017/3/15/14932718/google-chrome-browser-battery-life-tab-throttling I still feel like Corona suspending itself when a tab becomes inactive is a purposeful safety net because of how some browsers impose restrictions that Coronalabs can’t control. It’s safer for an app to be suspended than for it to continue trying to operate when the browser stops doing things like invoking timers at their proper intervals. Hacking this out of the binary because it’s annoying just seems a little dangerous to me…?

Yes, probably… I think the best behaviour would be for Corona to keep working as long as that tab was the selected window in the operating system, otherwise suspend.

So Corona keeps working (stays in focus, is not suspeneded) if the user selects other bits of that window, but if the window itself goes out of focus (in the OS) then it suspends.

However, I have zero idea how to do that. Having looked at the Corona code from github, it is beyond my skillset.