白色屏幕加载cocos2d场景

时间:2011-10-03 06:40:36

标签: iphone cocos2d-iphone

我是cocos 2d游戏开发的新手,开发了一个游戏,我需要多次从视图控制器重新加载场景。为此,我删除场景并再次运行。场景加载2次或更多次但发生白屏并在控制台中显示错误“OpenGL错误0x0506 in - [EAGLView swapBuffers]”。

这是我添加场景的代码 -

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

}

和删除场景的代码 -

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

请帮助我,我不知道问题出在哪里。 谢谢。

1 个答案:

答案 0 :(得分:0)

有两点需要注意:

  • 不要发布CCDirector!您需要做的就是调用stopAnimation,然后调用startAnimation
  • 不要从超级视图中删除openGLView。相反,只需隐藏它:[CCDirector sharedDirector] .openGLView hidden:YES]
相关问题