0

UIKit我有一个大部分使用的 iOS 应用程序,两个 bot 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方法执行的动画。

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

4

1 回答 1

2

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

于 2013-09-10T07:48:46.567 回答