free.hacknet.game.StartScreen.java Source code

Java tutorial

Introduction

Here is the source code for free.hacknet.game.StartScreen.java

Source

/*
 * This file is part of HackNet
 * Copyright (C) <2014>  <Ivan Kulikov>
 * This program 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.
 * 
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package free.hacknet.game;

import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenAccessor;
import aurelienribon.tweenengine.TweenEquations;
import aurelienribon.tweenengine.TweenManager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

import free.hacknet.game.tween.ImageAccessor;

public class StartScreen extends ScreenAdapter {
    // TODO fix later
    private Stage stage;
    private Image logoImage;
    private TweenManager tweenManager;

    public StartScreen() {
        Tween.registerAccessor(Image.class, new ImageAccessor());
        tweenManager = new TweenManager();
        stage = new Stage(new ScreenViewport());
        TextureParameter param = new TextureParameter();
        param.minFilter = TextureFilter.Linear;
        Assets.manager.load(Assets.HacknetLogoPath, Texture.class, param);
        Assets.manager.finishLoading();
        Table table = new Table();
        table.setFillParent(true);
        logoImage = new Image(Assets.manager.get(Assets.HacknetLogoPath, Texture.class));
        table.add(logoImage).center();
        logoImage.setColor(logoImage.getColor().a, logoImage.getColor().g, logoImage.getColor().b, 0f);
        stage.addActor(table);
        stage.setDebugAll(true);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        tweenManager.update(delta);
        stage.act(delta);
        stage.draw();
    }

    @Override
    public void show() {
        //Tween.to(logoImage, ImageAccessor.ColorAlpha, 255f).target(0).ease(TweenEquations.easeNone).start(tweenManager);
    }

    @Override
    public void pause() {
        tweenManager.pause();
    }

    @Override
    public void resume() {
        tweenManager.resume();
    }

    @Override
    public void dispose() {
        stage.dispose();
        Assets.manager.unload(Assets.HacknetLogoPath);
    }

}