在多个UIViewControllers中使用Cocos2D时,帧速率显着下降

时间:2013-09-10 02:17:39

标签: ios cocos2d-iphone uikit

我有一个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方法执行的动画。

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

1 个答案:

答案 0 :(得分:2)

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