Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx for android shows black before main screen

I am making a game in LibGDX, and I have noticed that when my game is launched a black screen is shown for a few moments before the white screen of my game is drawn.

I have set the background of my app's theme to be a different color with android:windowBackground in my app's style.xml, and the preview window shows that color. However, right before the main screen of my app loads, the screen goes black for a moment before displaying the main screen.

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

The only way I've found to fix this is to set the android:windowDisablePreview to true, but that disables the preview window all together.

Is there any way to fix this without disabling the preview?

like image 427
jjtcomkid Avatar asked Dec 19 '13 15:12

jjtcomkid


1 Answers

In addition to shifting objects creation to constructor, you also need to shift the ApplicationListener object creation in Activity class's constructor.

The black screen is probably because of the time delay between start of Activity.onCreate() call and end of ApplicationListener.show() call.
Try to measure it using a timer or simply System.currentTimeMillis() so the difference would be visible.

This should improve the situation if not eliminate the problem.

like image 196
Tanmay Patil Avatar answered Nov 18 '22 00:11

Tanmay Patil