Sign in to follow this  
mileafly

Possible to prevent device to go to sleep?

Recommended Posts

I am doing a concept for an "idle game" where the game is supposed to be playing itself apart from doing upgrades and stuff. This works well on desktop and browsers. But I think there will be a problem with mobiles that go to sleep if left alone. Is it possible to disable sleep mode somehow?

Share this post


Link to post
Share on other sites

Feasibility aside, many mobile users will be very upset if you run their battery down to zero by inhibiting sleep...

 

What's to stop you designing the game in such a way that the simulation can progress even if the screen is off?

Share this post


Link to post
Share on other sites

Don't prevent the app from going to sleep.  Horrible thing to do.  iOS/Android will let you know when the app is going to be deactivated and then brought back to the front.  Save your state when the game is going away and then calculate the difference when it comes back. 

 

For iOS the UIApplicationDelegate has 'applicationDidEnterBackground' and 'applicationWillEnterForeground' (also applicationWillResignActive/applicationDidBecomeActive).  And for Android the Activity has 'onStop' and 'onResume'.  Any decent third party engine will bubble those events up to the client code in some form.

Share this post


Link to post
Share on other sites

On iOS, there's [[UIApplication sharedApplication].idleTimerDisabled = TRUE;

 

This is designed for preventing screen fade when watching FMVs, or if your input is purely tilting. It might be suitable for your case, but as others suggest, you shouldn't leave the sleep timer disabled for any longer than necessary.

 

Ultimately though, if your gameplay involves not touching the screen for long periods of time, then idleTimerDisabled is the right thing to use.

Share this post


Link to post
Share on other sites

Could you design the game so that the game remembers the last time it was used (i.e. 9:09 PM 2014/8/24), and interpolates what "happened" the next time the user logs in? This would solve your problem (even when people shut down their desktops) and annoy users less. I wouldn't even want a browser page open continuously even on my desktop, unless it's something important.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this