Thursday, May 31, 2012

cocos2d-x resume from background issue...

I love cocos2d-x, it helps me to write games quickly on iOS and android with just one code base.

But I found a small problem that if my cocos2d-x games run into background, and when it get back to foreground, it will restart !

That means if you play my game for a while and a phone call just received, after you pick up the call, you will need to re-play the game from the very first stage.

That's bad, and I don't like it !

After a while googling, I found the solution, and I post here to make sure if someone have the same issue with me, and you can try this solution, it works for me, and maybe you too !

Step1 : open the AppDelegate.cpp

Step2 : make your code like below

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()

// if you use SimpleAudioEngine, it must be pause

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()

// if you use SimpleAudioEngine, it must resume here

Step3 : re-compile and run it

And that's all !!!

Hope you will enjoy your coding time !!!


  1. why do you have to stopAnimation and then pause? shouldn't it be only one of these?

  2. Sorry, but my phone is not stopped when i play cocos 2dx game app.

    it is not called "void AppDelegate::applicationDidEnterBackground()"
    please help me!

  3. I am new comer in android please tell, why this error occored -
    - CCDirector is not declared error

  4. Since this administration can furnish you with great data that you can truly trust, I would encourage you to put resources into background check administrations. This administration would guarantee you the fulfillment of conceivable costumers like you. Presently, don't hesitate! Make your turn and go for criminal background checks!background check services

  5. A resume writing administration that has tests accessible for you to investigate. Resume and introductory letter tests ought to be accessible on the site - archives that you can advantageously haul up and print out.certified professional resume writers

  6. Great blog. All posts have something to learn. Your work is very good and i appreciate you and hopping for some more informative posts. professional resume