Cocos2d-x 解决闪屏问题

一旦两个精灵图片交叠且移动的时候,偶尔会产生闪屏问题:即两个图片相互闪烁,仿佛引擎无法识别哪个是前景哪个是背景

切到CCDirector::setGLDefaultValues() 查看

 


复制代码
 1 void CCDirector::setGLDefaultValues(void)
 2 {
 3     // This method SHOULD be called only after openGLView_ was initialized
 4     CCAssert(m_pobOpenGLView, "opengl view should not be null");
 5 
 6     setAlphaBlending(true);
 7     setDepthTest(true);
 8     setProjection(m_eProjection);
 9 
10     // set other opengl default values
11     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
12 
13 #if CC_DIRECTOR_FAST_FPS
14     if (! m_pFPSLabel)
15     {
16         m_pFPSLabel = CCLabelTTF::labelWithString("00.0", "Arial", 24);
17         m_pFPSLabel->retain();
18     }
19 #endif
20 }
复制代码

发现第七行打开了深度测试,于是在AppDelegate::applicationDidFinishLaunching()中,添加一行:

CCDirector::sharedDirector()->setDepthTest(false);//关闭深度测试

成功解决

补充:还可以添加这行代码

CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);//使用2D投影(默认3D)

posted @ 2014-01-07 10:38  rshow  阅读(416)  评论(0编辑  收藏  举报