Keeping the screen on
You have to keep the device from entering into the sleep mode while playing your game. For example, in your game, the player can control the game and keep the game going by using the accelerometer. The problem is that if the player does not touch the screen while playing with the accelerometer, the device goes to sleep and enters background mode. In this recipe, you can keep the screen on easily.
How to do it...
You can keep the screen on if you set it to true
by using the Device::setKeepScreenOn
method as follows:
Device::setKeepScreenOn(true);
How it works...
There is a different way for each platform to prevent a device from entering the sleep mode. However, Cocos2d-x can do it for every platform. You can use this method without executing a platform. In the iOS platform, the setKeepScreenOn
method is as follows:
void Device::setKeepScreenOn(bool value) { [[UIApplication sharedApplication] setIdleTimerDisabled:(BOOL)value]; }
In the Android platform, the method is...