How do I pause on unfocus in NW.js?

  • So, I'm aware that unfocusing a tab in a browser will cause the game to suspend (effectively pausing anything happening on screen). But what about NW.js?

    I tried exporting my game to NW.js and testing this, but it doesn't seem to suspend when I unfocus from the window. Is this expected behavior? I notice that if I turn on the "Pause on unfocus" option when previewing in NW.js, it DOES suspend.

  • Maybe this will work for you?

  • donkeyspaceman <- forgot to tag you

  • Pause on unfocus

    If set to Yes, the preview will pause when the browser window loses focus, e.g. when switching back to work in Construct 2. This can be useful for certain workflows such as using continuous preview. If set to No the preview will continue to run even without focus, but note switching to another browser tab or minimising the browser window will still pause (as it does with published projects).

    Although the explanation in the manual isn't really clear about it, this setting is only meant for the preview.

    In the editor it is mentioned in the description:

    During preview only,whether to pause the game when browser loses focus.

  • LittleStain Have to say I see you in every thread Nice to see you're helping out a lot!

  • LittleStain Have to say I see you in every thread Nice to see you're helping out a lot!

    Just my way of keeping the mind active while taking breaks from my work.

    Why not use it to help others?

  • LittleStain Exactly I've been using Construct 2 and I've been on a massive dry spell for game ideas lately so I've just been browsing and helping as much as I can.

  • Maybe this will work for you?

    It doesn't. I've tried exactly that solution. I don't think NW.js considers the executable window losing focus to be the same as a browser windows losing focus.

    Pause on unfocus

    If set to Yes, the preview will pause when the browser window loses focus, e.g. when switching back to work in Construct 2. This can be useful for certain workflows such as using continuous preview. If set to No the preview will continue to run even without focus, but note switching to another browser tab or minimising the browser window will still pause (as it does with published projects).

    Although the explanation in the manual isn't really clear about it, this setting is only meant for the preview.

    In the editor it is mentioned in the description:

    During preview only,whether to pause the game when browser loses focus.

    Right, I understand that. I know that feature is of zero use. But when exporting, a browser game will always pause when unfocused and an executable will NEVER pause when unfocused. This is my issue, I'd like the NW.js build to work the same as the HTML5 export.

    Sorry if my original post was unclear.

  • I get what you mean now. But honestly why can't you just pause the game.. I mean if we're talking about a game here then why can't you just hit esc then that pauses the game. When you come back into the game and hit resume it just resumes. I don't see why that can't just be a work around?

  • http://www.filedropper.com/pause <- Run that you'll see what I mean then look at the event sheet.

  • I get what you mean now. But honestly why can't you just pause the game.. I mean if we're talking about a game here then why can't you just hit esc then that pauses the game. When you come back into the game and hit resume it just resumes. I don't see why that can't just be a work around?

    I wasn't able to open your example because you saved it on the newest beta (I'm on the r216 still), but I understand what you're saying. I have sort of a specific use case that I'm not expecting Scirra to support, but I was really just hoping there would be a solution I could use already available.

    My game will be playable on a large touchscreen table in my local public library. Users can open games from the Windows 8 Metro screen, at which point they go full screen. If a user presses the Windows button and returns to the Metro menu to pick another game, the library does not want my game to continue to produce sound while running in the background. So, the ideal solution in my use case would be an auto-suspend, as I can't expect the users (mostly small children) to press a pause button before abandoning my game.

    Now that I'm thinking about it, I wonder if exporting the game as a proper Windows 8 app might behave differently. I hadn't thought about it until this point because I wasn't planning on putting the game in the Windows Store, but it might be worth testing out.

  • Oh okay so you're issue is basically you're running multiply games inside on app? Can't you just set when they go back to the menu or press the button it stops music and speed for that layout?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sorry if I don't make sense I don't dev on windows I do android and web.

  • Oh okay so you're issue is basically you're running multiply games inside on app? Can't you just set when they go back to the menu or press the button it stops music and speed for that layout?

    No, the other apps would be other games, so the issue is with navigating the OS and not something I can handle inside Construct 2.

    Sorry if I don't make sense I don't dev on windows I do android and web.

    It's fine, I appreciate your suggestions either way.

  • Have you found a solution yet?

    I have the same issue (though, me it's for a PC game, not tablet)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)