2

I have a problem with a cocos2d 3.0 project for iPhone, where basically the animation stops when the app is sent to the background and does not start again when re-launching the app.

The whole Xcode project was copied exactly from another of mine which does not exhibit this bug, and the only major thing I've done is integrating a few ad networks (Chartboost and PlayHaven) - but I have commented out all of the ad code to test if that is the cause and that had no effect.

The working (older) project runs at 60 FPS (observed through the console entries that state cocos2d: animation started with frame interval: 60.00) and drops to 4 FPS when being sent to the background (standard cocos2d behaviour), and then restarts at 60 FPS when launched again. The project I'm having a problem with relaunches at 4 FPS, but even this is wrong - there is just no animation at all.

I have tried adding the following code in applicationDidBecomeActive:

[[CCDirector sharedDirector] setAnimationInterval:1.0/60];
[[CCDirector sharedDirector] startAnimation];

And this makes the console log when re-launching say 60 FPS rather than 4, but it still has no actual effect on animation - it's still just stopped.

James Webster
  • 31,873
  • 11
  • 70
  • 114
ttarik
  • 3,824
  • 1
  • 32
  • 51

1 Answers1

4

The problem seemed to be the existence of the applicationDidBecomeActive method in my app delegate - having that method with anything in it will stop cocos2d from restarting the animation properly.

The solution is to - inside your method - add a call to the superclass like so:
[super applicationDidBecomeActive:application];

I had Chartboost code in this method, which is why it was present in this project but not my older (working) one - and when I tested to see if the ad integration was the cause, I just commented out the Chartboost code rather than the whole method.

ttarik
  • 3,824
  • 1
  • 32
  • 51