se.theodor.quiz.screen.SplashScreen.java Source code

Java tutorial

Introduction

Here is the source code for se.theodor.quiz.screen.SplashScreen.java

Source

/********************************************************************************
 * 
 *   Copyright 2014 Theodor Angergard
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *******************************************************************************/

package se.theodor.quiz.screen;

import static se.theodor.quiz.util.Objects.BATCH;

import se.theodor.quiz.Quiz;
import se.theodor.quiz.tween.AlphaTween;

import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenEquations;
import aurelienribon.tweenengine.TweenManager;

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.graphics.g2d.Sprite;

public class SplashScreen implements Screen {

    public SplashScreen(Quiz quiz) {
        this.quiz = quiz;
    }

    private Texture texture_SplashScreen;
    private Sprite sprite_SplashScreen;
    private TweenManager tweenManager;
    private Quiz quiz;

    @Override
    public void render(float delta) {
        tweenManager.update(delta);
        BATCH.begin();
        sprite_SplashScreen.draw(BATCH);
        BATCH.end();
    }

    @Override
    public void resize(int width, int height) {
        sprite_SplashScreen.setSize(width, height);
        sprite_SplashScreen.setX(0f);
        sprite_SplashScreen.setY(0f);
    }

    @Override
    public void show() {
        texture_SplashScreen = new Texture(Gdx.files.internal("data/texture/SplashScreen.png"));
        sprite_SplashScreen = new Sprite(texture_SplashScreen);
        sprite_SplashScreen.setColor(1, 1, 1, 0);

        TweenCallback cb = new TweenCallback() {

            @Override
            public void onEvent(int type, BaseTween<?> source) {
                quiz.setScreen(new MainMenu(quiz));
            }

        };

        tweenManager = new TweenManager();
        Tween.to(sprite_SplashScreen, AlphaTween.ALPHA, 0f).target(1).ease(TweenEquations.easeInQuad)
                .repeatYoyo(1, .0000001f).setCallback(cb).setCallbackTriggers(TweenCallback.COMPLETE)
                .start(tweenManager);
    }

    @Override
    public void hide() {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

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

}