我在模拟器上运行我的cocos2d程序.它工作正常,但当我在设备上运行时,它会抛出错误OpenGL错误0x0506 - [CCSprite draw] 530和[CCGLView swapBuffers] 283.在我的程序中我想将一个场景推送到另一个场景.那时它显示错误和下一个场景的黑屏.请帮我解决一下.我也尝试谷歌.
注意:我的应用程序不会崩溃,但绘制精灵有问题.
我的代码如下:
首先加载LoadingLayer如下.
-(void) directorDidReshapeProjection:(CCDirector*)director { if ([[director runningScene] isRunning]) { [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer scene]]; } else { [[CCDirector sharedDirector] runWithScene:[LoadingLayer scene]]; } } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Create the main window window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.window setBackgroundColor:[UIColor whiteColor]]; glView = [CCGLView viewWithFrame:[window_ bounds] pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; director_ = (CCDirectorIOS*) [CCDirector sharedDirector]; director_.wantsFullScreenLayout = YES; // Display FSP and SPF [director_ setDisplayStats:NO]; // set FPS at 60 [director_ setAnimationInterval:1.0/60]; // attach the openglView to the director [director_ setView:glView]; // 2D projection [director_ setProjection:kCCDirectorProjection2D]; // [director setProjection:kCCDirectorProjection3D]; // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices if( ! [director_ enableRetinaDisplay:YES] ) CCLOG(@"Retina Display Not supported"); // Default texture format for PNG/BMP/TIFF/JPEG/GIF images // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565 // You can change this setting at any time. [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils]; [sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"]; // Default on iPhone RetinaDisplay is "-hd" [sharedFileUtils setiPadSuffix:@"-ipad"]; // Default on iPad is "ipad" [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"]; // Default on iPad RetinaDisplay is "-ipadhd" // Assume that PVR images have premultiplied alpha [CCTexture2D PVRImagesHavePremultipliedAlpha:YES]; // Create a Navigation Controller with the Director navController_ = [[MyNavigationController alloc] initWithRootViewController:director_]; navController_.navigationBarHidden = YES; // for rotation and other messages [director_ setDelegate:navController_]; // set the Navigation Controller as the root view controller [window_ setRootViewController:navController_]; // make main window visible [window_ makeKeyAndVisible]; return YES; }
在LoadingLayer之后,它推送到viewcontroller.it点击按钮转到HelloWorldLayer.
-(void)Button { director_ = (CCDirectorIOS*) [CCDirector sharedDirector]; [director_ replaceScene:[HelloWorldLayer scene]]; [self.navigationController pushViewController:director_ animated:YES]; }
作为场景流到viewcontroller到场景.
应用程序没有崩溃,但它有如下错误
在模拟器上它运行良好但CPU使用率达到95%到100%.
这只是一个cocos2d应用程序而不是UIKit混合应用程序吗?在这种情况下,当你只是简单地切换场景(CCScene)时,为什么要调用pushViewController?尝试删除:
[self.navigationController pushViewController:director_ animated:YES];
没有理由你应该推动导演,它已经存在.当您切换CCScene时,您没有创建新的视图控制器.