Hi all,
My application stop run when screen locked.
Is this a bug or cocos2d can't do that?
Please advise.
A fast, easy to use, free, and community supported 2D game engine
Hi all,
My application stop run when screen locked.
Is this a bug or cocos2d can't do that?
Please advise.
Correct me if i'm wrong, but I think that applications are suspended when the screen is locked. All apps, not just Cocos2D.
@liquidfire: yes, everything is suspended.
no.... wait... if you mean "locked", the "locked" that appears when you don't touch the screen for 1 minute, then it should continue working
Not on iPhone OS 4 on hardware with multitasking support any more. You have to initiate background taks. Hope I didn't break Apple NDA now :-).
Use this code to prevent lock...
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Keep this into AppDelegate..didfinishlaunch.
First I don't want to disable the screen-lock. That means the following is not suitable:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Second, there is a way to keep the app run when screen locked, that is play a silent sound each 10 seconds. There is a MMPDeepSleepPreventer doing this job. Please refer to http://github.com/marcop/MMPDeepSleepPreventer for detail.
I used this class, and find the sound playing code is working when scree locked, but the mail loop for cocos2d is not working.
If you can try it, you will see what i say.
Thanks.
Jacky.
What do you have in your applicationWillResignActive? My guess is you are pausing the Director there.
That MMPDeepSleepPreventer class is just a hack, setting the audio session category to MediaPlayback allows any application to continue playing sound while the phone is locked. However, if you set the audio session category to MediaPlayback then it kills all other audio on the device so that means the user can't be listening to music on the iPod while playing your game.
I commented this function and also the applicationDidBecomeActive function.
^ then it is probably to do with the director type. Try different director types but as I said before that MMPDeepSleepPreventer is a hack and there is no guarantee it is going to work on 4.x.
You must log in to post.