ios - 在多个 UIViewController 中使用 Cocos2D 时帧率明显下降

标签 ios cocos2d-iphone uikit

我有一个大部分使用 UIKit 的 iOS 应用,两个 UIViewController 的 bot,我使用 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。由于 director 是单例,暂停/恢复会影响两个 View 。

关于ios - 在多个 UIViewController 中使用 Cocos2D 时帧率明显下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18709762/

相关文章:

iphone - 复制 xib 文件的最佳方法是什么?

ios - UIView/UICoordinateSpace 在 swift 3 中转换矩形/点冲突

ios - 将表情符号编码为字符串

ios - Objective-C:如何从 NSDate 获取日期和日期?

ios - UIView +animateWithDuration : isn't animating a recently allocated view correctly

iphone - iOS Oblique TextView 在 Cocos2D 或 native 中滚动

cocos2d-iphone - IOS游戏中如何使用Lua作为数据存储?

ios - 在点击不可选择的单元格后,先前选择的 UICollectionViewCells 被取消选择

iphone - 在 iOS 中,当 View 动画已经在设置动画时启动它会发生什么?

ios - GameplayKit 寻路使用什么算法?