1

I am trying to make a splash screen wait for 10 seconds.
I tried searching everywhere and tried a few methods, but nothing seems to work.

Anyone to lead me to the right direction?

Here is my code:

public class SplashLoadingScreen extends Screen {

public SplashLoadingScreen(Game game) {
    super(game);
}

@Override
public void update(float deltaTime) {
    Graphics g = game.getGraphics();
    Assets.splash= g.newImage("splash.jpg", ImageFormat.RGB565);
    game.setScreen(new LoadingScreen(game));
}

@Override
public void paint(float deltaTime) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}

@Override
public void dispose() {
}

@Override
public void backButton() {
}
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Simon Sari
  • 21
  • 6

3 Answers3

1

Try using Handler to give the delay.

//handler to close the splash activity after sometime
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                //Call your image from assests
            }

        }, 10000);

Hope this helps.

Thanks

Anurag
  • 469
  • 3
  • 5
0

Similarly to my answer here, you should use the update method to update a timer that will initiate the screen change.

public class SplashLoadingScreen extends Screen {

private Sprite sprite;
private Texture texture;

public SplashLoadingScreen(Game game) {
    super(game);
    texture = new Texture(Gdx.files.internal("data/splash.png");
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    sprite = new Sprite(new TextureRegion(texture, 0, 0, imageWidth, imageHeight);

}

private float timer = 0.0f;

@Override
public void update(float deltaTime) {
    timer += deltaTime;
    if(timer > 10) {
        game.setScreen(new LoadingScreen(game));
    }
}

@Override
public void paint(float deltaTime) {
    spriteBatch.draw(sprite);
}

@Override
public void pause() {
}

@Override
public void resume() {
}

@Override
public void dispose() {
    texture.dispose();
}

@Override
public void backButton() {
}
}
Community
  • 1
  • 1
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
-1
public class SplashLoadingScreen extends Screen {
public SplashLoadingScreen(Game game) {
      super(game);
}

@Override
public void update(float deltaTime) {

Graphics g = game.getGraphics();
Assets.splash= g.newImage("splash.jpg", ImageFormat.RGB565);
try { 
Thread.currentThread(); 
Thread.sleep(10000); 
} catch (InterruptedException e) { 
e.printStackTrace(); 
}
game.setScreen(new LoadingScreen(game));
}

@Override
public void paint(float deltaTime) {
}


@Override
public void pause() {
}

@Override
public void resume() {
}


@Override
public void dispose() {
}
}
Magesh Vs
  • 82
  • 4
  • this seems to work.. but for some reason the Wait is working on the black screen that appears before the splash.jpg screen – Simon Sari Apr 05 '15 at 07:57