Package com.palepail.TestGame.Screens

Source Code of com.palepail.TestGame.Screens.MainMenu

package com.palepail.TestGame.Screens;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.palepail.TestGame.TestGame;
import com.palepail.TestGame.Utilities.Audio;

public class MainMenu implements Screen {

  TestGame game;
  Stage stage;
  BitmapFont bonzai;
 
  TextureAtlas atlas;
  Skin skin;
  SpriteBatch batch;
  TextButton button;
  Label label;

  public MainMenu(TestGame game) {
    this.game = game;
    Audio.setMusic("menu");
    Audio.setVolume();
    Audio.playMusic(true);
  }

  @Override
  public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    Gdx.input.setInputProcessor(stage);
    stage.act(delta);
   
    batch.begin();
    stage.draw();
    batch.end();

  }

  @Override
  public void resize(int width, int height) {
    if (stage == null) {
      stage = new Stage(width, height, true);
    }
    stage.clear();
   
    Gdx.input.setInputProcessor(stage);
   
    TextButtonStyle style = new TextButtonStyle();
    style.up = skin.getDrawable("buttonnormal");
    style.down = skin.getDrawable("buttonpressed");

    style.font = bonzai;
    style.fontColor= Color.BLACK;
    button = new TextButton("Press Me", style);
    button.setWidth(400);
    button.setHeight(100);
    button.setX(Gdx.graphics.getWidth() / 2 - button.getWidth() / 2);
    button.setY(Gdx.graphics.getHeight() / 2 - button.getHeight() / 2);

    button.addListener(new InputListener() {
      public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
        System.out.println("down");
        return true;
      }

      public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
        System.out.println("up");
        Audio.stopMusic();
        Audio.ok();
        game.setScreen(new GameScreen(game));
      }
    });

   
 
    LabelStyle ls = new LabelStyle(bonzai,Color.WHITE);
    label = new Label("Test Game", ls);
    label.setX(0);
   
    label.setY(Gdx.graphics.getHeight()/2+100);
    label.setWidth(width);
    label.setAlignment(Align.center);

   
    stage.addActor(button);
    stage.addActor(label);
  }

  @Override
  public void show() {
    batch = new SpriteBatch();
    skin = new Skin();
    atlas = new TextureAtlas("data/buttons/button.pack");
    skin.addRegions(atlas);
    bonzai = new BitmapFont(Gdx.files.internal("data/fonts/bonzai32.fnt"),
        Gdx.files.internal("data/fonts/bonzai32.png"), false);
  }

  @Override
  public void hide() {
    // TODO Auto-generated method stub

  }

  @Override
  public void pause() {
    // TODO Auto-generated method stub

  }

  @Override
  public void resume() {
    // TODO Auto-generated method stub

  }

  @Override
  public void dispose() {
    batch.dispose();
    skin.dispose();
    atlas.dispose();
    bonzai.dispose();
    stage.dispose();
  }

}
TOP

Related Classes of com.palepail.TestGame.Screens.MainMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.