[Tutorial - Mobile] Prevent the screen of the mobile device from falling asleep

Hello everyone!

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:

  • in the game project during the start of the scene (starting for the game) add the JavaScript code:
    window.plugins.insomnia.keepAwake();
    This is done once. Now the smartphone screen will not fall asleep. To disable you need to execute the code:
    window.plugins.insomnia.allowSleepAgain();
  • now you need to add a plugin:
    1. upload the project to a folder as indicated in the documentation;
    2. install Node.js, Cordova (if not already installed):
      npm install -g cordova
    3. add the plugin to the project:
      cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git
    4. follow the instructions, add a project for Android:
      cordova platform add android
    5. we build (via the console or Android Studio):
      cordova build android

I checked this method in my game New Year Postcard (details in the post on the forum).

2 Likes

OMG Thats Crazy Thanks Bro
Wish I Could use that In My Video tuto By giving Credits…:sweat_smile:

1 Like

Thank you, I’m glad it might come in handy for someone.
If you want, tell me about my game, I will be very grateful.

P.S. If you are going to teach manual assembly of a mobile application for Android, then do not forget to tell about the requirements from Google (Create and set up your app - Play Console Help). Otherwise, it will not work to load the game on Google Play, and when unloading the project from GDevelop, they are not taken into account (as it seemed to me, I did not see the settings in config.xml).

1 Like

Wᴏᴀʜʜʜʜ Mᴀɴ
ɪ ᴅɪᴅɴᴛ sᴇᴇ ᴛʜᴇ ɢᴀᴍᴇ ʟɪɴᴋ ɪɴ ғɪʀsᴛ sɪɢʜᴛ
Bᴜᴛ Tʜɪs ɢᴀᴍᴇ ɪs Hᴇᴀᴠʏʏʏʏʏʏʏ
Tʜᴇ Fᴀᴅɪɴɢ Aɴɪᴍᴀᴛɪᴏɴ
ᴡᴏᴀʜʜʜʜʜʜʜ
Fɪʀsᴛʟʏ ɪ ᴅɪᴅɴᴛ ᴜɴᴅᴇʀsᴛᴀɴᴅ Tʜᴇ Gᴀᴍᴇ
Bᴜᴛ Tʜᴇɴ ɪᴛ ɪs ᴇɴᴊᴏʏᴀʙʟᴇ ᴡʜᴇɴ ɪ sᴛᴀʀᴛᴇᴅ ᴛᴏ ᴋɴᴏᴡ ᴀʙᴏᴜᴛ ᴛʜɪs ɢᴀᴍᴇ
Iᴛ sᴜʀᴇʟʏ ᴛᴏᴏᴋ ʏᴏᴜ ᴍᴜᴄʜ ᴛɪᴍᴇ ??

1 Like

Thank you for your feedback!
Development lasted 6 weeks. It started on November 1st as part of the Game Jam, and on December 13th I was already uploading the 4th update (minor edits).

1 Like

In what sense is it heavy? Complex?

In my community heavy means its Awesome

1 Like

That looks like it took alot of time
You did it all alone?

Well, 6 weeks in the evenings (2-3 hours), in fact not much, but the project is small.

The music was handled by Rosko Vair. I also tested and did localization during the competition.