O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Keeping the screen alive

In the previous section we added the accelerometer interaction to our game, which means that our player is controlling the main character by moving the phone rather than by touching the screen, this will cause many android devices to turn off the screen after a period of inactivity (not touching the screen). Of course, no one would like that our Android device's screen suddenly goes black; in order to prevent this from happening, we will call the setKeepScreenOnJni method, introduced in the previous version 3.3 of the framework. Prior to this version, this annoying situation was considered a framework flaw, and now it has finally been fixed.

We first need to include the helper in our HelloWorldScene.cpp header file as follows: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required