Libgdx for Android shows black in front of the main screen

I am making a game in LibGDX, and I noticed that when my game is running, the black screen is displayed for a few seconds until the white screen of my game is drawn.

I set the background color of my application to a different color with android:windowBackground in my application style.xml , and the preview window shows this color. However, before the main screen of my application loads, the screen will appear black before displaying the main screen.

I tried setting Gdx.gl.glClearColor(1,1,1,1) in the main activity and game class in my game, but the black screen still shows for a moment before drawing the main screen.

The only way I decided to fix this is to set the android:windowDisablePreview to true, but this completely disables the preview window.

Is there a way to fix this without disabling preview?

+6
source share
1 answer

In addition to moving the creation of objects to the constructor, you also need to shift the creation of the ApplicationListener object to the constructor of the Activity class.

The black screen is probably due to the time delay between the start of the call to Activity.onCreate () and the end of the call to ApplicationListener.show (). Try measuring it using a timer or just System.currentTimeMillis (), so the difference will be visible.

This should improve the situation, if not fix the problem.

+2
source

All Articles