Android splash screen are basically used to show Company logo for a couple of second before the app loads completely. In this article we are going to learn how to implement splash screen in your android application.
// This is the game class of your game.
public class CreatioGame extends Game
{
@Override
public void create()
{
this.setScreen(new Splash(this));
// This is how you call a screen
}
}
// This class is called form game class. All the loading of assets of your game is done here.
public class Splash implements Screen
{
private SpriteBatch spriteBatch;
private Texture splsh;
private Game myGame;
/**
* Constructor for the splash screen
* @param g Game which called this splash screen.
*/
public Splash(Game g)
{
myGame = g;
}
@Override
public void render(float delta)
{
// first we will clear the screen
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// draw the splash image here
spriteBatch.begin();
spriteBatch.draw(splsh, 0, 0);
spriteBatch.end();
// This switches the screen if user touches the screen. Normally you will require this once all the assets are loaded in you game.
// will show you how to load Assets in your game in next Blog.
if(Gdx.input.justTouched())
myGame.setScreen(new GameScreen());
}
// this method is called once when screen is called. Initialize your varialbes here.
@Override
public void show()
{
spriteBatch = new SpriteBatch();
splsh = new Texture(Gdx.files.internal(“splash.png”));
}