在多个 UIViewController 中使用 Cocos2D 时帧速率显著下降



我有一个iOS应用程序,大部分时间使用UIKit,机器人两个UIViewController,我使用Cocos2D

我像这样设置Cocos2D

@implementation CocosScreen1 {
    @private
    CCDirectorIOS* director;    
    CCScene* scene;
    CCLayer* comicLayer;
    UINavigationBar* navBar;
    UIView* bottomOptionsBar;
    CCGLView *glView;
}

-(void) setupCocos2d; {
    glView = [CCGLView viewWithFrame:self.view.bounds pixelFormat:kEAGLColorFormatRGB565                                   depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];    
    director = (CCDirectorIOS*) [CCDirector sharedDirector];
    director.wantsFullScreenLayout = YES;
    [director setAnimationInterval:1.0/60]; // set FPS at 60
    [director setView:glView];  // attach the openglView to the director
    [director setDelegate:self]; // for rotation and other messages
    [director setProjection:kCCDirectorProjection2D];   // 2D projection
    if( ! [director enableRetinaDisplay:YES] )
    CCLOG(@"Retina Display Not supported");
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
    [sharedFileUtils setEnableFallbackSuffixes:NO]; 
    [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];
    [sharedFileUtils setiPadSuffix:@"-ipad"];
    [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
    CCScene* bottomScene = [CCScene node];
    [director pushScene:bottomScene];
    scene = [CCScene node];
    comicLayer = [[AgComicLayer alloc] initWithOptionsView:optionsParentView withReaderScreenReference:self];
    UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonSystemItemCancel target:self action:@selector(backButtonTapped)];
    [self.navigationItem setBackBarButtonItem:backButton];        
}

然后两个屏幕在出现之前调用了这个:

-(void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];  
    [self.view insertSubview:director.view atIndex:0];  
    [[CCDirector sharedDirector] startAnimation];    
    [director pushScene:scene];
}

然后两个屏幕在消失时调用了这个:

-(void) viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [[CCDirector sharedDirector] pause];
    [director popScene];
}

发生的事情是其中一个屏幕工作得很好。然而,另一个Cocos2D场景的帧率从 60 大幅下降到 4。并且它无法启动通过runAction方法执行的动画。

我需要解决帧率问题,并让第二个场景正确恢复并播放动画。我的实现有什么问题?对于我想要实现的目标,是否有最佳实践?

恢复导演。您正在暂停它,但永远不会恢复。暂停意味着将 fps 降低到 4。由于导演是单例暂停/恢复会影响两种视图。

最新更新