1

I am having a application in cocos2d-x. I want my application should run always until manually stops. But while enters into the background it got paused and when return back it resumes. I removed the codes

CCDirector::sharedDirector()->pause();
CCDirector::sharedDirector()->resume();

from Appdelegate.cpp functions (applicationDidEnterBackground() and applicationDidEnterForeground()). But still my application got pause while enter into background.I want my application should pause only when i got a phone call or manually i pause my application, until or unless it should run in the background. Please me to solve this.

socrates
  • 124
  • 10

1 Answers1

0

Here is what happens when your app goes to background

class name >>> Cocos2dxActivity.java

    @Override
    protected void onPause() {
    super.onPause();

    Cocos2dxHelper.onPause();
    this.mGLSurfaceView.onPause();
}

I think the code is self explanatory,i.e, it is pausing your app when it enters background (the whole purpose of onPause) and the ApplicationDelegate methods you mentioned are just JNI functions called when the activity goes to background/foreground so that you can do game related stuff there. As you may know that CCDirector's pause only pauses the running scene (scheduled timers) and changes the draw rate to 4 FPS to reduce CPU consumption.

So, removing pause/resume calls to CCDirector in Appdelegate will not help achieve those goals. For that you have to override the method and related methods I mentioned above and stop the activity from pausing.

Syed Mauze Rehan
  • 1,125
  • 14
  • 31
  • but I am doing it for IOS using c++ then where i can make changes – socrates May 28 '14 at 06:28
  • Check your AppController.mm file, from there the calls are made to the AppDelegate.cpp file. – Syed Mauze Rehan May 28 '14 at 07:07
  • I tried but its not working. now i want my application should run while device is locked. I tried but i couldn't make it, can you please suggest me where i can get the solution. – socrates May 28 '14 at 12:06
  • What do you wish to achieve by making it that way? May be there is an alternate to it! – Syed Mauze Rehan May 28 '14 at 12:15
  • my application is based on audio, for certain time it should keep on making sound. but when i locks the device the application got paused and while unlock it resumes from last session.But i want my application to make sound while device is locked. – socrates May 28 '14 at 12:25
  • There is one answer in there... check it out, http://stackoverflow.com/questions/12475034/how-to-stop-and-resume-background-audio-from-iphone-app .... – Syed Mauze Rehan May 28 '14 at 12:52
  • thanks for your comment, but that's not my concept.I want my application should run while the device is locked. – socrates May 28 '14 at 13:06
  • Yes I know, I was mentioning the last comment which says not to deactivate your audio session, may be this is what you are looking for. – Syed Mauze Rehan May 28 '14 at 13:18
  • And this, http://stackoverflow.com/questions/10429204/how-to-handle-background-audio-playing-while-ios-device-is-locked-or-on-another Try exploring the "CDAudioManager" file in COCOSDENSHION... – Syed Mauze Rehan May 28 '14 at 13:46