[feature req] detect browser & nw not in focus / blurred

Discussion and feedback on Construct 2

Post » Thu Jul 02, 2015 2:11 pm

Presently the Browser object will return triggers On Suspended and On Resumed when the game tab comes back into focus when switching back from a new tab or if the game was minified into the task bar. For very sensible security reasons, a blurred or out of focus game is unable to register key down and key up triggers during the time is is blurred - which means that the c2 key is down will incorrectly register a key position as down if it misses the key up trigger. If you code your events only using key down/up triggers then you also cannot detect key triggers when the game is out of focus. Using the browser On Suspended and Resumed triggers allows you to code your events to manage the possibility of missing key triggers.

However, it is not possible for c2 developers to set events to detect if the player has returned to a running game after they have clicked on something else on their desktop - although the game loses focus and becomes blurred, the triggers will not fire when focus is regained. For example, if the game is not minified and another program is opened over the top of it then these triggers will not fire, and if the game was in a stand alone browser window and the player just clicks on something else then the triggers will not fire on returning as well.

If you're exporting in nw then these can make your game look rather amateur when the player clicks on something else accidentally or just opens another program momentarily - and then, when they return to the fruits of your hard work, they discover (for example) that they are stuck in a run-right-to-suicide loop until they press the Right key again (the right key release trigger being missed by the game logic).

Now, the debug "pause on unfocus" option clearly uses a more complete not in focus / blur detection system than the aforementioned browser triggers - because it will pause the game in the above 2 situations during preview. This feature request is to give us access to this same blurred / out of focus condition information.

Anyone any thoughts / ideas / comments / work-arounds?
A big fan of JavaScript.
B
76
S
20
G
73
Posts: 2,241
Reputation: 45,956

Post » Thu Jul 02, 2015 2:56 pm

I think it would be better to fix this directly in the keyboard/mouse object: if the window loses focus, then it will immediately fire mouse up/key up triggers for any keys which were held down. Then keys never get stuck, and games don't have to reinvent this feature every time in the events if they want to avoid the problem. Does that sound reasonable?
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,351

Post » Thu Jul 02, 2015 2:58 pm

@Ashley - that sounds excellent :).
A big fan of JavaScript.
B
76
S
20
G
73
Posts: 2,241
Reputation: 45,956


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 4 guests