Java tutorial
/* * Copyright: * This file was created by BinaryTENSHi and distributed * as part of NoPassing. * * NoPassing lies under a license which can be * found in the LICENSE file in the root directory * File created @ [26.12.2013, 19:04:40 CH timezone] */ package com.binarytenshi.nopassing.state; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.binarytenshi.nopassing.NoPassing; import com.binarytenshi.nopassing.core.CameraHandler; import com.binarytenshi.nopassing.lib.FileHelper; import com.binarytenshi.nopassing.lib.Path; public class MenuGameScreen implements Screen { private final Stage stage; private final Image background; public MenuGameScreen() { stage = new Stage(); background = new Image(new Texture(FileHelper.getFile(Path.Menu, "back.png"))); Texture playTexture = new Texture(FileHelper.getFile(Path.Menu, "play.png")); Texture quitTexture = new Texture(FileHelper.getFile(Path.Menu, "quit.png")); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(new TextureRegion(playTexture, 1024, 256)); Button playButton = new Button(style); playButton.setBounds(25, 50, 128, 32); playButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { NoPassing.instance.setScreen(GameScreen.Game.getScreen()); } }); style = new ButtonStyle(); style.up = new TextureRegionDrawable(new TextureRegion(quitTexture, 1024, 256)); Button quitButton = new Button(style); quitButton.setBounds(CameraHandler.getCamera().viewportWidth - 25 - 128, 50, 128, 32); quitButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Gdx.app.exit(); } }); stage.addActor(background); stage.addActor(playButton); stage.addActor(quitButton); } @Override public void render(float delta) { Camera camera = CameraHandler.getCamera(); Rectangle viewport = CameraHandler.getViewport(); camera.update(); camera.apply(Gdx.gl10); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glViewport((int) viewport.x, (int) viewport.y, (int) viewport.width, (int) viewport.height); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); float w = camera.viewportWidth; float h = camera.viewportHeight; stage.setViewport(w, h); background.setBounds(0, 0, w, h); stage.draw(); } @Override public void resize(int width, int height) { } @Override public void show() { Gdx.input.setInputProcessor(stage); } @Override public void hide() { } @Override public void pause() { } @Override public void resume() { } @Override public void dispose() { } }