2014-01-24 53 views
0

我是新的cocos2d.I使用cocos2d(3.0 Beta)平臺與uiview進行遊戲。我在自定義viewcontroller中設置GLView。以下是我的代碼。GlView導致OpenGL錯誤

- (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];** 

    } 

它的工作fine.But當我們把對象然後給我繼內存worning。

OpenGL error 0x0506 in -[CCSprite draw] 544 
OpenGL error 0x0502 in -[CCGLView swapBuffers] 287** 

我認爲,當我們調用([[CCDirector sharedDirector] setView:glView])的setView方法它找不到CCDirector方法,但UIView的method.I無法訪問CCDirector method.Same方法我也不能在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]; 
} 
+0

使用下面的代碼是OpenGL的錯誤,而不是一個內存警告。你所做的設置cocos2d看起來並不正確。我不認爲autoresizing支持。你知道導演是一個視圖控制器嗎? – LearnCocos2D

+0

@ LearnCocos2D ya.it的opengl錯誤。我不需要自動更新。所有的東西都顯示正常。但是當我們添加精靈對象然後錯誤生成。有些時候性能是如此之多的減少。我沒有在設備中測試。 Thanx爲您的重播。 –

+0

@ LearnCocos2D我的代碼在2.0版本中運行良好,但在3.0版本中無法運行。 –

回答

0

您在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]; 


} 
+0

我試過了。我的項目在2.0中工作得很好,但在最新的cocos2d 3.0中沒有工作Alpha版本。 –