Background transparency in libgdx

房东的猫 提交于 2019-12-18 05:18:10

问题


How can I make background of screen transparent if I use libgdx in Android?

The code I tried to use doesn't work.

Gdx.gl.glClearColor( 0, 0, 0, 0 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT );

回答1:


Just found a solution!

Just add this code to the class that extends 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);
}



回答2:


Think it this way - transparency is visible when you have at least two things. If you have a black background and then draw a white one on top of it with transparency say 50%, you will see black background through your white layer. Now, at the start you have the screen. It can be of any color. Under that screen, there's nothing. So, if you need transparency, draw something on top of it with alpha channel.



来源:https://stackoverflow.com/questions/17966338/background-transparency-in-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!