To set the COCOS2DX background as a transparent method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.