Advertisement
Guest User

MainMenu.java

a guest
Aug 25th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. public class MainMenu implements Screen{
  2.  
  3.     private Game game;
  4.     private Stage stage;
  5.     private Table table;
  6.     private Skin skin;
  7.     private TextureAtlas atlas;
  8.     private TextButton playButton;
  9.     private BitmapFont white;
  10.     private Label heading;
  11.     private Label.LabelStyle headingStyle;
  12.  
  13.     public MainMenu(Game gam){
  14.         game = gam;
  15.  
  16.         stage = new Stage();
  17.  
  18.         Gdx.input.setInputProcessor(stage);
  19.  
  20.         white = new BitmapFont(Gdx.files.internal("fonts/white.fnt"), false);
  21.  
  22.         atlas = new TextureAtlas("ui/button.pack");
  23.  
  24.         skin = new Skin(atlas);
  25.  
  26.         table = new Table(skin);
  27.         table.setFillParent(true);
  28.  
  29.         TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle();
  30.         buttonStyle.up = skin.getDrawable("buttonUp");
  31.         buttonStyle.down = skin.getDrawable("buttonDown");
  32.         buttonStyle.pressedOffsetX = 1;
  33.         buttonStyle.pressedOffsetY = -1;
  34.         buttonStyle.font = white;
  35.         buttonStyle.fontColor = Color.BLACK;
  36.  
  37.         playButton = new TextButton("PLAY", buttonStyle);
  38.         playButton.pad(30);
  39.         playButton.addListener(new ChangeListener() {
  40.             @Override
  41.             public void changed(ChangeEvent event, Actor actor) {
  42.                 game.setScreen(new GamePlay());
  43.             }
  44.         });
  45.  
  46.         headingStyle = new Label.LabelStyle(white, Color.WHITE);
  47.         heading = new Label(GAMETITLE, headingStyle);
  48.         heading.setFontScale(1);
  49.  
  50.  
  51.         table.add(heading);
  52.         table.getCell(heading).spaceBottom(100);
  53.         table.row();
  54.         table.add(playButton);
  55.         table.debug();
  56.         stage.addActor(table);
  57.  
  58.     }
  59.  
  60.     @Override
  61.     public void render(float delta) {
  62.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  63.  
  64.         table.act(delta);
  65.         stage.draw();
  66.  
  67.     }
  68.  
  69.     @Override
  70.     public void dispose() {
  71.         stage.dispose();
  72.         atlas.dispose();
  73.         skin.dispose();
  74.         white.dispose();
  75.     }
  76.  
  77.     @Override
  78.     public void show() {
  79.  
  80.     }
  81.  
  82.     @Override
  83.     public void resize(int width, int height) {
  84.  
  85.     }
  86.  
  87.     @Override
  88.     public void pause() {
  89.  
  90.     }
  91.  
  92.     @Override
  93.     public void resume() {
  94.  
  95.     }
  96.  
  97.     @Override
  98.     public void hide() {
  99.  
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement