libgdx中的背景透明度

use*_*694 3 android background opengl-es libgdx

如果我在Android中使用libgdx,如何才能使屏幕背景透明?

我试图使用的代码不起作用.

Gdx.gl.glClearColor( 0, 0, 0, 0 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT );
Run Code Online (Sandbox Code Playgroud)

use*_*694 12

刚刚找到解决方案!

只需将此代码添加到扩展AndroidApplication的类中.

AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.r = cfg.g = cfg.b = cfg.a = 8;

cfg.useGL20 = false;

View view = initializeForView(new LineDrawing(), cfg);

if (graphics.getView() instanceof SurfaceView) {
            SurfaceView glView = (SurfaceView) graphics.getView();
            glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
            glView.setZOrderOnTop(true);
}
Run Code Online (Sandbox Code Playgroud)