com.bossletsplays.rr.screens.SplashScreen.java Source code

Java tutorial

Introduction

Here is the source code for com.bossletsplays.rr.screens.SplashScreen.java

Source

/*   Copyright 2014 Matthew Rogers "BossLetsPlays"
*
*   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 com.bossletsplays.rr.screens;

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

import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.bossletsplays.rr.Ragdoll;
import com.bossletsplays.rr.gfx.Texture2D;
import com.bossletsplays.rr.libs.Reference;
import com.bossletsplays.rr.libs.TweenTypes;
import com.bossletsplays.rr.tweens.SpriteAccessor;
import com.bossletsplays.rr.utils.RenderUtil;
import com.bossletsplays.rr.utils.Util;

/**
 * <strong>Project:</strong> Ragdoll Rick-core <br>
 * 
 * <strong>Class:</strong> SplashScreen
 * 
 * @author <a href = "http://www.youtube.com/BossLetsPlays"> BossLetsPlays</a>
 */
public class SplashScreen implements Screen {

    private Sprite splash;
    private SpriteBatch batch;
    private TweenManager tweenManager;

    @Override
    public void render(float delta) {
        RenderUtil.clearColor(0.0f);
        RenderUtil.clear(GL20.GL_COLOR_BUFFER_BIT);

        tweenManager.update(delta);

        batch.begin();
        splash.draw(batch);
        batch.end();
    }

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

    @Override
    public void show() {
        batch = new SpriteBatch();
        tweenManager = new TweenManager();
        Tween.registerAccessor(Sprite.class, new SpriteAccessor());

        splash = Texture2D.getSprite("splashscreen");
        splash.setSize(Util.getWidth(), Util.getHeight());

        Tween.set(splash, TweenTypes.ALPHA).target(0).start(tweenManager); //target(0) allows alpha value to start at 0, so it can fade in first
        float delay = Reference.DEBUG ? 0.5f : 2.0f; //make the splashscreen finish faster when in development
        Tween.to(splash, TweenTypes.ALPHA, delay).target(1).repeatYoyo(1, delay).setCallback(new TweenCallback() {
            @Override
            public void onEvent(int type, BaseTween<?> source) {
                Ragdoll.getInstance().setScreen(new MainMenu());
            }
        }).start(tweenManager); //Fade in, pause, fade out
    }

    @Override
    public void hide() {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void dispose() {
        Texture2D.dispose(batch, splash);
    }

}