开发者

White screen to load cocos2d scene

开发者 https://www.devze.com 2023-04-10 09:36 出处:网络
I am new in cocos 2d game development anddeveloping a game where I need to reload scenes fr开发者_Python百科om view controller many times.For this i remove the scene and run it again.After 2 or more t

I am new in cocos 2d game development and developing a game where I need to reload scenes fr开发者_Python百科om view controller many times.For this i remove the scene and run it again.After 2 or more times the scene loads but white screen occurs and in console the error "OpenGL error 0x0506 in -[EAGLView swapBuffers]" is shows.

here is my code to add the scene-

             if ([[CCDirector sharedDirector] runningScene] == NULL) 
             {
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];

    CCDirector *director = [CCDirector sharedDirector];

    glView = [EAGLView viewWithFrame:[window bounds]
                                   pixelFormat:kEAGLColorFormatRGBA8
                                   depthFormat:GL_DEPTH_COMPONENT24_OES
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:YES
                               numberOfSamples:4];




    [director setOpenGLView:glView];        
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];   
    [director setAnimationInterval:1.0/60];
    [window addSubview:glView];     

    [[CCDirector sharedDirector] runWithScene: [HelloWorldLayer node]];

}

and code for remove the scene-

[[CCDirector sharedDirector].openGLView removeFromSuperview];
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] end];
[[CCDirector sharedDirector] release];

Please help me I am not getting where is the problem. Thanks.


Two things of note:

  • don't release CCDirector! All you need to do is call stopAnimation and later startAnimation
  • don't remove the openGLView from its super view. Instead, just hide it: [CCDirector sharedDirector].openGLView hidden:YES]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号