Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Keep game running out of focus
Started by usacb Jan 23 2019 02:03 PM

- - - - -
19 replies to this topic
html5 focus backgroud
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

usacb

[GLOBAL: userInfoPane.html]
usacb
  • Observer

  • 7 posts
  • Corona SDK

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. 


  • prographodeveloper likes this

[TOPIC: post.html]
#2

lg5200

[GLOBAL: userInfoPane.html]
lg5200
  • Observer

  • 13 posts
  • Corona SDK

++++



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,539 posts
  • Enterprise

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


  • hiramatsu likes this

[TOPIC: post.html]
#4

lg5200

[GLOBAL: userInfoPane.html]
lg5200
  • Observer

  • 13 posts
  • Corona SDK

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

  • hiramatsu likes this

[TOPIC: post.html]
#5

hiramatsu

[GLOBAL: userInfoPane.html]
hiramatsu
  • Observer

  • 1 posts
  • Corona SDK

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.


  • efgames.net likes this

[TOPIC: post.html]
#6

mr.badim

[GLOBAL: userInfoPane.html]
mr.badim
  • Observer

  • 3 posts
  • Corona SDK

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

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


  • prographodeveloper and pixec like this

[TOPIC: post.html]
#7

efgames.net

[GLOBAL: userInfoPane.html]
efgames.net
  • Contributor

  • 221 posts
  • Corona SDK

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)


  • prographodeveloper and pixec like this

[TOPIC: post.html]
#8

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

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.


  • pixec likes this

[TOPIC: post.html]
#9

efgames.net

[GLOBAL: userInfoPane.html]
efgames.net
  • Contributor

  • 221 posts
  • Corona SDK

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/



[TOPIC: post.html]
#10

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

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.


  • pixec likes this

[TOPIC: post.html]
#11

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 101 posts
  • Corona SDK

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

[TOPIC: post.html]
#12

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 502 posts
  • Corona SDK

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?
  • sporkfin likes this

[TOPIC: post.html]
#13

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 330 posts
  • Corona SDK

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.
 

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?

 

 

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.



[TOPIC: post.html]
#14

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 330 posts
  • Corona SDK

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.



[TOPIC: post.html]
#15

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,539 posts
  • Enterprise

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


  • prographodeveloper likes this

[TOPIC: post.html]
#16

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 330 posts
  • Corona SDK

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.



[TOPIC: post.html]
#17

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 330 posts
  • Corona SDK

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.


  • mr.badim likes this

[TOPIC: post.html]
#18

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 842 posts
  • Corona SDK

There are instructions at the bottom of this page, though admittedly they're pretty sparse.  :) 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.


  • pixec likes this

[TOPIC: post.html]
#19

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 502 posts
  • Corona SDK

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...?

[TOPIC: post.html]
#20

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 330 posts
  • Corona SDK

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.

 




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: html5, focus, backgroud