2011-10-19 52 views
4

some cocos2d-iphone documentation,有人告诉我,把这个无法设置深度缓冲区?

// IMPORTANT: Call this function at the very beginning, before running your 1st scene 
// Create a depth buffer of 24 bits 
// These means that openGL z-order will be taken into account 
[[CCDirector sharedDirector] setDepthBufferFormat:kDepthBuffer16]; 

为了让我在游戏中的行动与一些3D效果。但是,由于某些原因,Xcode不识别setDepthBufferFormatkDepthBuffer16。有任何想法吗?

回答

6

不幸的是,cocos2d文档部分过期。你提到的方法不再存在。相反,您将不得不修改初始化EAGLView的应用程序委托方法applicationDidFinishLaunching中的行。有一个“viewWithFrame”变体,需要depthFormat的额外参数:

// Create an EAGLView with a RGB8 color buffer, and a depth buffer of 24-bits 
EAGLView* glView = [EAGLView viewWithFrame:[window bounds] 
           pixelFormat:kCCTexture2DPixelFormat_RGBA8888 
           depthFormat:GL_DEPTH_COMPONENT16_OES 
         preserveBackbuffer:NO 
           sharegroup:nil 
          multiSampling:NO 
          numberOfSamples:0]; 
+0

啊。谢谢。顺便说一下,你知道为什么当我运行3D动作时,背景会变黑吗? – Voldemort

+1

可能是因为缺少深度缓冲区。您可能还必须启用深度测试:[[CCDirector sharedDirector] setDepthTest:YES]; – LearnCocos2D