Ios GlView导致OpenGL错误
我是cocos2d新手。我正在用uiview和cocos2d(3.0测试版)平台进行游戏。我在自定义viewcontroller中设置了GLView。下面是我的代码Ios GlView导致OpenGL错误,ios,cocoa-touch,opengl-es,cocos2d-iphone,Ios,Cocoa Touch,Opengl Es,Cocos2d Iphone,我是cocos2d新手。我正在用uiview和cocos2d(3.0测试版)平台进行游戏。我在自定义viewcontroller中设置了GLView。下面是我的代码 - (void)setupCocos2D { CCGLView *glView = [CCGLView viewWithFrame:self.view.bounds pixelFormat:kEAGLColorFormatRGB565 depthFormat:0];** glView.autore
- (void)setupCocos2D {
CCGLView *glView = [CCGLView viewWithFrame:self.view.bounds pixelFormat:kEAGLColorFormatRGB565 depthFormat:0];**
glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:glView atIndex:0];
[[CCDirector sharedDirector] setView:glView];**
}
它工作得很好。但当我们放上object时,请给我以下内存警告。
OpenGL error 0x0506 in -[CCSprite draw] 544
OpenGL error 0x0502 in -[CCGLView swapBuffers] 287**
我认为当我们调用([[CCDirector sharedDirector]setView:glView])
setView方法时,它不是查找CCDirector方法,而是UIView方法。我无法访问CCDirector方法。同样的方法我也无法在AppDelegate类中调用
- (void)applicationWillTerminate:(UIApplication *)application {
CCDirector *director = [CCDirector sharedDirector];
//openGLView is now (setView in Latest version).It's Can't Access here.**
[[director openGLView] removeFromSuperview];
[director end];
}
您可以在setupCocos2D中使用以下代码
- (void)setupCocos2D
{
[[CCDirector sharedDirector] end];
UIWindow *window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window_ setBackgroundColor:[UIColor whiteColor]];
CCGLView *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];
}
这是opengl错误,不是内存警告。设置cocos2d的方法看起来根本不正确。我认为还不支持自动调整大小。你们知道director是一个viewcontroller吗?@learncos2D ya。这是opengl错误。我不需要自动浏览。所有东西都显示得很好。但当我们添加sprite对象时,会产生错误。有时性能会下降很多。我没有在设备中测试过。Thanx感谢您的重播。@LearnCos2D我的代码在2.0中运行良好,但在3.0版本中不起作用。由于3.0仍然是alpha版本,因此可能会坚持使用2.0,并且大多数肯定会包含bug。@LearnCos2D感谢您的重播。因此,我认为这一阶段我最好使用2.0而不是3.0?最新的3.0测试版也发布了,但不包含install.sh(安装文件)。我试过了。我的项目在2.0中运行良好,但在最新的cocos2d 3.0 Alpha版本中无法运行。