Search code examples
objective-ccocos2d-iphonespritebuilder

Using applicationDidBecomeActive makes app lag and slow after awakening it


NOTE: This only happens when I use cocos2d and spritebuilder. I tried the same exact code with just a single view app which worked fine.

When using applicationDidBecomeActive to send an NSLog, the app becomes laggy and slow upon being reopened. This is an extremely simple app so it does not have to do with intensive graphics or processes.

MainScene.m

#import "MainScene.h"

@implementation MainScene

int score;

-(void)digButton {
    score++;
    scoreLabel.string = [NSString stringWithFormat:@"%i", score];
}
@end

then this is the method in appdelegate.

-(void)applicationDidBecomeActive:(UIApplication *)application
{
    NSLog(@"hi");
}

Does this method not work correctly with cocos2d or something?


Solution

  • Make sure to call the super implementation o CCAppDelegate methods:

    -(void)applicationDidBecomeActive:(UIApplication *)application
    {
        NSLog(@"hi");
        [super applicationDidBecomeActive:application];
    }
    

    Without that the default CCAppDelegate implementation won't run, which resumes the director:

    -(void) applicationDidBecomeActive:(UIApplication *)application
    {
        [[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
        if( [navController_ visibleViewController] == [CCDirector sharedDirector] )
            [[CCDirector sharedDirector] resume];
    }