将 cocos2dx 背景 设置 成 透明 的方法
下面 为 从 网络上 搜索到的 将 cocos2dx 背景 设置成 透明的 方法, android 层,自己 亲测 OK,但是 需要 将glSurfaceView.setZOrderOnTop(true); 这句话 注释掉。否则 会有 问题。 android 层 还有 一个 貌似 可行的 方法(没测过):http://www.52php.cn/article/p-nxjbzgdk-wo.html 至于 ios 端,自己 没测试,博友 可以 参考一下。
android层: public Cocos2dxGLSurfaceView onCreateView() {Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); // hello should create stencil buffer //glSurfaceView.setEGLConfigChooser(5,6,5,16,8);//modify glSurfaceView.setEGLConfigChooser(8,8,0); //glSurfaceView.setZOrderOnTop(true); glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); return glSurfaceView; } C++层: void CCDirector::setGLDefaultValues(void) { // This method SHOULD be called only after openGLView_ was initialized CCAssert(m_pobOpenGLView,"opengl view should not be null"); setAlphaBlending(true); // XXX: Fix me,should enable/disable depth test according the depth format as cocos2d-iphone did // [self setDepthTest: view_.depthFormat]; setDepthTest(false); setProjection(m_eProjection); // set other opengl default values //glClearColor(0.0f,0.0f,1.0f);//modify glClearColor(0.0f,0.0f); 即可实现透明效果
补充IOS 上可以参考这个方法变成透明背景: 参考网址:http://www.cocoachina.com/bbs/read.php?tid-156363-page-2.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |