加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

将 cocos2dx 背景 设置 成 透明 的方法

发布时间:2020-12-14 21:40:08 所属栏目:百科 来源:网络整理
导读:下面 为 从 网络上 搜索到的 将 cocos2dx 背景 设置成 透明的 方法, android 层,自己 亲测 OK,但是 需要 将 glSurfaceView.setZOrderOnTop(true); 这句话 注释掉。否则 会有 问题。 android 层 还有 一个 貌似 可行的 方法(没测过):http://www.jb51.cc/

下面 为 从 网络上 搜索到的 将 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://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里的默认背景色设置,改为透明。不同版本处理略有差异

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读