Search code examples
javaandroidimagelibgdxsplash-screen

How can I create a SplashScreen in LibGDX that goes through 3 images before showing the main menu?


I'm doing a college project where I need to make a game for Android using a Java framework, and for now all I have to do is make the splashscreen for the game like described in the title/question, but I didn't even manage to make the texture (png file) scale to fit the screen. So, how can I make a simple splashscreen that goes through some images after a set delay or input before going to the main menu?


Solution

  • Time Delay

    float delay = 1; // seconds
    
    Timer.schedule(new Task(){
        @Override
        public void run() {
            // Do your work
        }
    }, delay);
    

    The above code helps you delay the execution, and after that delay you can perform the action you want.

    Here, Inside the run method you can switch to any screen and ofcourse you can use this function as many times as you want.

    Fitting the image to the screen

    batch.draw(texture,0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());