我有一个用Cocos2d编写的游戏。最重要的是,我展示了一些UIKit对象。Cocos2d与UIKit视图混合 - 巨大的FPS下降
然后,我添加了一个UIViewController来处理使用UIKit对象和UIView动画编写的单独迷你游戏。我用这个添加到我的Cocos2D场景中的代码如下:
gameVC = [[[UGameViewController alloc]
initWithNibName:@"UGameViewController" bundle:nil]
retain];
[[[CCDirector sharedDirector] openGLView] addSubview:gameVC.view];
gameVC.parentClass = self;
[gameVC viewDidAppear:YES];
的UIKit的游戏的初始化发生在viewDidAppear:
方法,这就是为什么我把它从控制器。
当以这种方式添加视图时,我注意到我在那里使用的动画(缩放+翻译+视图翻转)非常非常不连贯。在我的iPad上运行应用程序并查看CoreAnimation工具可以显示出戏剧性的FPS下降 - 从cocos2d场景中的40-60 fps到UIKit部件上的4-8 fps。
有什么我可以做的,以便以某种方式解决它?
编辑:我CCDirector初始化是这样的:
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
window = [[ShakeEnabledUIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Try to use CADisplayLink director
// if it fails (SDK < 3.1) use the default director
if(! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink])
[CCDirector setDirectorType:kCCDirectorTypeDefault];
CCDirector *director = [CCDirector sharedDirector];
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
//
// Create the EAGLView manually
// 1. Create a RGB565 format. Alternative: RGBA8
// 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
//
//
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565
depthFormat:0
preserveBackbuffer:NO];
[director setOpenGLView:glView];
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif
[director setAnimationInterval:1.0/60];
// make the OpenGLView a child of the view controller
[viewController setView:glView];
// make the View Controller a child of the main window
[window addSubview: viewController.view];
[window makeKeyAndVisible];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [Main scene]];
}
向我们展示您的CCDirector初始化plz – klefevre
它来自标准cocos2d模板。编辑问题以添加该信息。 – kender