The following is a way to set the COCOS2DX background to transparent from a network search.
Android layer, self-test OK, but need to be glsurfaceview.setzorderontop (true); This sentence is commented out. Otherwise there will be a problem.
The Android layer also has a plausible method (not measured): http://blog.csdn.net/ypist/article/details/8805422
As for iOS, I did not test, Bo friends can refer to.
Android Layer:
Public Cocos2dxglsurfaceview Oncreateview () {
Cocos2dxglsurfaceview Glsurfaceview = new Cocos2dxglsurfaceview (this);
//Hello should create stencil buffer
//Glsurfaceview.seteglconfigchooser (5, 6, 5, 0, +, 8);//modify
Glsurfaceview.seteglconfigchooser (8, 8, 8, 8, +, 0);
Glsurfaceview.setzorderontop (true);
Glsurfaceview.getholder (). SetFormat (pixelformat.translucent);
return glsurfaceview;
}
C + + layer:
void ccdirector::setgldefaultvalues (void)
{
//This method should is called only after Openglview_ is initialized
Ccassert (M_pobopenglview, "OpenGL view should not being 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, 0.0f, 1.0f);//modify
Glclearcolor (0.0f, 0.0f, 0.0f, 0.0f);
}
For transparent effects
Supplement iOS can refer to this method to become transparent background:
Http://blog.sina.com.cn/s/blog_6957e2e50101bxf1.html
The point is that first pixelformat:keaglcolorformatrgba8 must have an alpha layer to be transparent.
then the view is set to transparent
glview.opaque = NO;
[director Setopenglview:glview];
[Self.viewController.view setbackgroundcolor:[uicolor clearcolor];
[Self.viewController.view Addsubview:glview];
in version 3.3, I was searching for Glclearcolor within the project and changed the default background color setting in CCDirector.cpp to Transparent. Different versions of processing differ slightly
Glclearcolor (0.0f, 0.0f, 0.0f, 0.0f);
Reference URL: http://www.cocoachina.com/bbs/read.php?tid-156363-page-2.html
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
To set the COCOS2DX background as a transparent method