ca.hiphiparray.amazingmaze.SplashScreen.java Source code

Java tutorial

Introduction

Here is the source code for ca.hiphiparray.amazingmaze.SplashScreen.java

Source

/********************************************************************************
 * Amazing Maze is an educational game created in Java with the libGDX library.
 * Copyright (C) 2017 Hip Hip Array
 *
 * This file is part of Amazing Maze.
 *
 * Amazing Maze is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Amazing Maze is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Amazing Maze. If not, see <http://www.gnu.org/licenses/>.
 *******************************************************************************/

package ca.hiphiparray.amazingmaze;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

/**
 * @since 1.0.1
 * @author Vincent Macri
 * <br>
 * Time (Vincent): 10 minutes
 */
public class SplashScreen implements Screen {

    /** The {@link AmazingMazeGame} instance that is managing this screen. */
    private final AmazingMazeGame game;

    /** The {@link Stage} for the splash screen. */
    private final Stage stage;

    /** The company logo. */
    private Image logo;

    /**
     * Create the splash screen.
     *
     * @param game the {@link AmazingMazeGame} instance that is managing this screen.
     */
    public SplashScreen(final AmazingMazeGame game) {
        this.game = game;
        this.stage = new Stage(new ScreenViewport(), game.batch);

        Table table = new Table();
        table.setFillParent(true);
        table.center();
        stage.addActor(table);

        logo = new Image(this.game.assets.manager.get(Assets.COMPANY_LOGO, Texture.class));
        logo.addAction(Actions.sequence(Actions.alpha(0), Actions.delay(1f), Actions.fadeIn(1f), Actions.delay(1f),
                Actions.fadeOut(1f)));

        table.add(logo);
    }

    @Override
    public void show() {
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        if (!logo.hasActions()) {
            game.setScreen(game.menuScreen);
        }

        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void hide() {
        dispose();
    }

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

}