This method will help to make the smartphone fall asleep during the game. You do this as a setting and let the player decide whether to enable it or not.
To add this functionality, you need to use the plugin for
Cordova. This means that you can also assemble the mobile version of the game by hand, as described in the documentation (Publish your game to Android and iOS manually using Cordova [GDevelop wiki]). This plugin is called Insomnia-PhoneGap-Plugin.
I will not describe the complete order (only briefly), what needs to be done to build (you can see this in the documentation), but I will indicate the steps for installing the plugin and the necessary code in the game project. Procedure:
This is done once. Now the smartphone screen will not fall asleep. To disable you need to execute the code:
- now you need to add a plugin:
- upload the project to a folder as indicated in the documentation;
Cordova(if not already installed):
npm install -g cordova
- add the plugin to the project:
cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git
- follow the instructions, add a project for Android:
cordova platform add android
- we build (via the console or Android Studio):
cordova build android