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

前端之家收集整理的这篇文章主要介绍了将 cocos2dx 背景 设置 成 透明 的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

android 层 还有 一个 貌似 可行的 方法(没测过):http://www.jb51.cc/article/p-nxjbzgdk-wo.html@H_403_3@@H_403_3@@H_403_3@

至于 ios 端,自己 没测试,博友 可以 参考一下。@H_403_3@@H_403_3@@H_403_3@


@H_403_3@@H_403_3@@H_403_3@

android层:@H_403_3@

public Cocos2dxGLSurfaceView onCreateView() {@H_403_3@
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);@H_403_3@
// hello should create stencil buffer@H_403_3@
//glSurfaceView.setEGLConfigChooser(5,6,5,16,8);//modify@H_403_3@
@H_403_3@
glSurfaceView.setEGLConfigChooser(8,8,0);@H_403_3@
//glSurfaceView.setZOrderOnTop(true);@H_403_3@
glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);@H_403_3@
return glSurfaceView;@H_403_3@
}@H_403_3@
C++层:@H_403_3@
void CCDirector::setGLDefaultValues(void)@H_403_3@
{@H_403_3@
// This method SHOULD be called only after openGLView_ was initialized@H_403_3@
CCAssert(m_pobOpenGLView,"opengl view should not be null");@H_403_3@

setAlphaBlending(true);@H_403_3@
// XXX: Fix me,should enable/disable depth test according the depth format as cocos2d-iphone did@H_403_3@
// [self setDepthTest: view_.depthFormat];@H_403_3@
setDepthTest(false);@H_403_3@
setProjection(m_eProjection);@H_403_3@
// set other opengl default values@H_403_3@
//glClearColor(0.0f,0.0f,1.0f);//modify@H_403_3@
glClearColor(0.0f,0.0f);@H_403_3@

即可实现透明效果@H_403_3@


@H_403_3@

补充IOS 上可以参考这个方法变成透明背景:@H_403_3@
http://blog.sina.com.cn/s/blog_6957e2e50101bxf1.html

要点是首先pixelFormat:kEAGLColorFormatRGBA8,必须有alpha层才能透明。@H_403_3@
然后view设置为透明@H_403_3@
glView.opaque = NO;@H_403_3@
[director setOpenGLView:glView];@H_403_3@
[self.viewController.view setBackgroundColor:[UIColor clearColor]];@H_403_3@
[self.viewController.view addSubview:glView];@H_403_3@
在3.3 版本下,我是在项目内搜索glClearColor,把CCDirector.cpp里的默认背景色设置,改为透明。不同版本处理略有差异@H_403_3@
403_3@
@H_403_3@


@H_403_3@@H_403_3@

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

猜你在找的Cocos2d-x相关文章