iPhone auto-lock while playing

I experience that the iPhone dims the screen down, preparing for auto-lock, while playing. I use the accelerometer for player control, so the might be a while without user touch input. Is there a way to prevent this from happening, without telling people to turn up the auto-lock time. :slight_smile:

Edit:
Ping @britzl @sicher @jakob.pogulis

I don’t know about a solution with Defold that would work right now, but looks like this is the kind of style native devs use

-(void)callEveryTwentySeconds
{
// DON’T let the device go to sleep during our gameplay
[[UIApplication sharedApplication] setIdleTimerDisabled:NO]; // required hack
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}

If that kind of thing was possible in Defold then you could detect lack of any accelerometer movement at all after so long and then allow it to auto lock again.

If you’d like, you can test our beta 1.2.86 which contains a new lua module window. if you call window.set_dim_mode(window.DIMMING_OFF) and window.set_dim_mode(window.DIMMING_ON), you will disable/enable screen dimming respectively. There is also a window.get_dim_mode()for convenience.

This is good for ingame vs menu/pause behavior. Beware of the added battery drain though (as I’m sure you anticipated).

Note that the actual release is only a few days away.

6 Likes