How do I prevent the screen from timing out?

  • Had a search and couldn't find anything specific to C3. Basically, during cutscenes, my game's screen begins to time out around the 1 minute mark (both Android and iOS) which isn't ideal as the user then needs to tap the screen or shortly after the device locks out.

    Now, someone had the suggestion that I have tap to proceed through cutscenes, as user input overrides the timeout, but unfortunately my cutscenes are timed to play specific scenes in line with audio track positions, so having the user set the transition time will stuff that up.

    Is there something in C3 that I've missed that will let me prevent the screen timeout? I have other apps on my phone (Android) that do this, so know it's at least a possibility.

    Cheers

  • github.com/richtr/NoSleep.js

    Now, how to incorporate that into C3???

  • Yeah, I have no idea how to use that. Surely this is a pretty common thing that people want to be able to access in their apps. I wonder why it's not already in Construct 3?

  • Been playing around with this today. I have it half working in that I can prevent the screen from timing out using the nosleep.js method, but I can't for the life of me get it to turn back off when the cutscene is finished.

    For reference, I'm using this guide davidwalsh.name/wake-lock-shim and adding the script using the manual method.

    Everything is good except the noSleep.disable(); doesn't seem to trigger. Tried creating a global variable to track it but had no luck.

  • Apparently that js isn't maintained any more. Here's a fork of the original updated as of last year. Might try it.

    github.com/shinyshoe/mosleep

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • An update to this thread. I grabbed the Construct Master Collection by chadorireborn yesterday and saw that it had a plugin called 'mobile sleep' in there.

    Gave it a whirl just then, and it does exactly what I wanted in the op. Very elegant too, just a single action when you want the screen to lock, and again when you want it to unlock.

    I did note that the screen times out as soon as you unlock it unless you tie it to a touch trigger (which makes sense).

    chadorirebornxd.itch.io/construct-master-collection

    Probably too expensive if all you wanted was that one plugin, but I guess I lucked out as I bought the set without even knowing it was in there.

  • Ohh that. Yeah, that plugin has been on the collection for a while now. The bonus side when you force it to awake is that, it forces the device to use its full performance.

    The performance part was the one I was truly after. This is because, as I've noticed, Cordova apps are sometimes performance throttled by device manufacturers to save up battery life because they assume Cordova apps are just office apps and didn't expect them to be games. Hence, this plugin forces them to use near full performance since the screen is on full. This is similar to Full Performance on a PC.

  • Is that still an issue with the c3 runtime? And if so, would you suggest leaving it on all the time?

    I had the slight concern that it would get rejected from the App Store if the screen was forced on. Sounds like that won't be the case.

  • LukeW

    Is that still an issue with the c3 runtime? And if so, would you suggest leaving it on all the time?

    It's the case for all Cordova apps, regardless of what runtime you use. Cordova builds hybrid apps, which Construct 3 uses to wrap HTML5 games for mobile.

    I suggest leaving it on during gameplay. But when on the menu, for example, you can turn it off. The plugin lets you choose when to lock or unlock.

    The ones throttling the performance are the device manufacturers, they filter out which to run their device's performance to its full extent and which to run idle mode, to save battery life.

    I tested this myself on a few devices. And I got a huge performance boost during locking.

    Not only that, if you wait for your application to reach a time that it goes idle mode when you don't use the plugin, it will have a huge FPS drop. Which is terrible for games especially realtime multiplayer.

    Though, this a device-specific case, not all devices have this. But I assume most devices that promotes battery life have this trick, which device manufacturers call smart battery, which is a feature, they're not wrong. But, it throttles the performance of Cordova games.

    Assuming for example 50% of devices have this 'smart battery' feature, you'd have 50% players not running your game on the full extent of their phone's hardware.

    As much as possible, it's recommended to run your games to the full extent of a device's performance.

    I had the slight concern that it would get rejected from the App Store if the screen was forced on. Sounds like that won't be the case.

    Nope, it won't. And it helps that you can just turn it on when you need it, for example during in-game.

  • I tested this myself on a few devices. And I got a huge performance boost during locking.

    I just tested this on my son's s4 and it made such a massive difference in framerate that he couldn't believe it.

    It did tank again as soon as I turned on replace colour for skin modes, but that's a different issue.

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