我有一个奇怪的情况,如果我的应用程序进入后台并回到前台,动画会以某种方式累积并应用超快速。例如一个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];
}
是什么导致这种情况发生?
答案 0 :(得分: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];
}
}
你可以恢复类似的方式。