我有一个大部分使用 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/