Cocos2dx background transparent processing
Take the latest Cocos2d-x 3.2 release as an example to explain how to make the background transparent in the Cocos2d-x.
Same, first.
There are not many changes. There are three main steps.
1. Set Activity background transparency in AndroidManifest. xml
?
VcmRlcj0 = "0" cellpadding = "0" cellspacing = "0">
| 1 |
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" |
,
2. Modify the init () method in the Cocos2dxActivity. java file in the org. cocos2dx. lib project of the libcocos2dx project.
Add the following code:
?
| 123 |
this.mGLSurfaceView.setZOrderOnTop(true);this.mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);this.mGLSurfaceView.setEGLConfigChooser(8,8,8,8,16,0); |
Delete the following code (if it is not deleted, there will be a Cocos2dxEditText white bar at the top. Cocos2dxEditText encapsulates EditText, which is mainly used for TextField. If it is used in the program, it is recommended to replace it with EditBox)
?
| 12 |
//mFrameLayout.addView(edittext);//this.mGLSurfaceView.setCocos2dxEditText(edittext); |
,
3. Modify the onSurfaceCreated () method in the Cocos2dxRenderer. java file in the org. cocos2dx. lib project of the libcocos2dx project.
Add the following code:
?
| 12345 |
pGL10.glDisable(GL10.GL_DITHER);pGL10.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);pGL10.glClearColor(0,0,0,0);pGL10.glEnable(GL10.GL_CULL_FACE);pGL10.glShadeModel(GL10.GL_SMOOTH); |
,
Well, if you have a better solution, please follow the post.