1

我有一个奇怪的情况,如果我的应用程序进入后台并回到前台,动画会以某种方式累积并以超快的速度应用。例如,CCRotateBy 会赶上应用程序在后台运行的时间并快速旋转精灵。

我认为我的应用程序委托具有正确的应用程序状态处理..

- (void)applicationWillResignActive:(UIApplication *)application {
    [[CCDirector sharedDirector] pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [[CCDirector sharedDirector] resume];
    [[OALAudioSession sharedInstance] forceEndInterruption];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    [[CCDirector sharedDirector] purgeCachedData];
}

-(void) applicationDidEnterBackground:(UIApplication*)application {
    [[CCDirector sharedDirector] stopAnimation];
}

-(void) applicationWillEnterForeground:(UIApplication*)application {
    [[CCDirector sharedDirector] startAnimation];
    [[OALAudioSession sharedInstance] forceEndInterruption];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    CCDirector *director = [CCDirector sharedDirector];

    [[director view] removeFromSuperview];

    [director end];
}

- (void)applicationSignificantTimeChange:(UIApplication *)application {
    [[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}

是什么导致这种情况发生?

4

1 回答 1

0

这是我们在使用 cocos2d 2.0 时面临的问题之一。

TEMP_FIX:我使用手动暂停动画。

-(void) applicationWillResignActive:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"AppEnterBackground" object:nil];

    if( [navController_ visibleViewController] == director_ )
        [director_ pause];
}



//In game layer

-(void)onEnter
{
    [super onEnter];
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(AppEnterBackground:) name:@"AppEnterBackground" object:nil];

}

-(void)onExit
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"AppEnterBackground" object:nil];
    [super onExit];
}

-(void)AppEnterBackground:(NSNotification*)notif
{
    [self pauseSchedulerAndActions];

    [mHero pauseSchedulerAndActions];

    for(MyCoin *coin in mCoinArr)
    {
       [coin  pauseSchedulerAndActions];
    }
}

类似的方式你可以恢复。

于 2013-07-17T15:14:09.983 回答