I made the game in libgdx and i want the splash screen in the starting but its show splash screen but not move to the game screen. I don't know what was the problem even the run time error also not occur.
GameScreen. java
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.gamestudio24.martianrun.stages.GameStage;
public class GameScreen implements Screen {
private GameStage stage;
public GameScreen() {
stage = new GameStage();
}
@Override
public void render(float delta) {
//Clear the screen
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//Update the stage
stage.draw();
stage.act(delta);
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
GdxSplashScreenGame. java
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Timer;
public class GdxSplashScreenGame extends Game {
private static long SPLASH_MINIMUM_MILLIS = 2000L;
public GdxSplashScreenGame() { super(); }
@Override
public void create () {
setScreen(new SplashScreen());
final long splash_start_time = System.currentTimeMillis();
new Thread(new Runnable() {
@Override
public void run() {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
long splash_elapsed_time = System.currentTimeMillis() - splash_start_time;
if (splash_elapsed_time < GdxSplashScreenGame.SPLASH_MINIMUM_MILLIS) {
Timer.schedule(
new Timer.Task() {
@Override
public void run() {
GdxSplashScreenGame.this.setScreen(new SplashScreen());
}
}, (float)(GdxSplashScreenGame.SPLASH_MINIMUM_MILLIS - splash_elapsed_time) / 1000f);
} else {
GdxSplashScreenGame.this.setScreen(new SplashScreen());
}
}
});
}
}).start();
}
@Override
public void dispose() {
// DISPOSE ALL RESOURCES
getScreen().dispose();
Gdx.app.exit();
}
}
SplashScreen. java
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class SplashScreen extends GameScreen {
private SpriteBatch batch;
private Texture ttrSplash;
public SplashScreen() {
super();
batch = new SpriteBatch();
ttrSplash = new Texture("assets/splash.png");
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(ttrSplash, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.end();
}
@Override
public void hide() { }
@Override
public void pause() { }
@Override
public void resume() { }
@Override
public void show() { }
@Override
public void resize(int width, int height) { }
@Override
public void dispose() {
ttrSplash.dispose();
batch.dispose();
}
}
MartianRun. java
import com.badlogic.gdx.Game;
import com.gamestudio24.martianrun.screens.GameScreen;
import com.gamestudio24.martianrun.screens.SplashScreen;
import com.gamestudio24.martianrun.utils.AssetsManager;
import com.gamestudio24.martianrun.utils.AudioUtils;
import com.gamestudio24.martianrun.utils.GameEventListener;
import com.gamestudio24.martianrun.utils.GameManager;
public class MartianRun extends Game {
public MartianRun(GameEventListener listener) {
GameManager.getInstance().setGameEventListener(listener);
}
@Override
public void create() {
AssetsManager.loadAssets();
setScreen(new SplashScreen());
setScreen(new GameScreen());
}
@Override
public void dispose() {
super.dispose();
AudioUtils.dispose();
AssetsManager.dispose();
}
}