Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了将 cocos2dx 背景 设置 成 透明 的方法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

下面 为 从 网络上 搜索到的 将 cocos2dx 背景 设置成 透明的 方法,

android 层,自己 亲测 OK,但是 需要 将glSurfaceView.setZOrderOnTop(true); 这句话 注释掉。否则 会有 问题。

android 层 还有 一个 貌似 可行的 方法(没测过):http://www.voidcn.com/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://blog.sina.com.cn/s/blog_6957e2e50101bxf1.html

要点是首先pixelFormat:kEAGLColorFormatRGBA8,必须有alpha层才能透明。
然后view设置为透明

glView.opaque = NO;
[director setOpenGLView:glView];
[self.viewController.view setBACkgroundColor:[UIColor clearColor]];
[self.viewController.view addSubview:glView];
在3.3 版本下,我是在项目内搜索glClearColor,把CCDirector.cpp里的默认背景色设置,改为透明。不@R_66_11197@处理略有差异
:rgb(51,0.0f);


网址:http://www.cocoachina.com/bbs/read.php?tid-156363-page-2.html

大佬总结

以上是大佬教程为你收集整理的将 cocos2dx 背景 设置 成 透明 的方法全部内容,希望文章能够帮你解决将 cocos2dx 背景 设置 成 透明 的方法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。