List of usage examples for com.badlogic.gdx.utils.viewport FitViewport FitViewport
public FitViewport(float worldWidth, float worldHeight)
From source file:com.github.mkjensen.breakall.Breakall.java
License:Apache License
private void createRenderer() { world = new World(); FitViewport viewport = new FitViewport(world.getSize(), world.getSize()); stage = new Stage(viewport); debugRenderer = new DebugRenderer(world, stage.getCamera()); Gdx.input.setInputProcessor(stage);/* www. j av a 2 s . com*/ }
From source file:es.danirod.jumpdontdie.game.CreditsScreen.java
License:Open Source License
public CreditsScreen(final MainGame game) { super(game);/* w ww . j a v a2 s . com*/ // Create a new stage, as usual. stage = new Stage(new FitViewport(640, 360)); // Load the skin file. The skin file contains information about the skins. It can be // passed to any widget in Scene2D UI to set the style. It just works, amazing. skin = new Skin(Gdx.files.internal("skin/uiskin.json")); // For instance, here you see that I create a new button by telling the label of the // button as well as the skin file. The background image for the button is in the skin // file. back = new TextButton("Back", skin); credits = new Label("Jump Don't Die v1.0.1\n" + "Copyright (C) 2015 Dani Rodriguez\n" + "This game is GNU GPL. Get the code at github.com/danirod/JumpDontDie\n\n" + "Music: \"Long Time Coming\" Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0", skin); // Add capture listeners. Capture listeners have one method, changed, that is executed // when the button is pressed or when the user interacts somehow with the widget. They are // cool because they let you execute some code when you press them. back.addCaptureListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Take me to the game screen! game.setScreen(game.menuScreen); } }); // Now I position things on screen. Sorry for making this the hardest part of this screen. // I position things on the screen so that they look centered. This is why I make the // buttons the same size. credits.setPosition(20, 340 - credits.getHeight()); back.setSize(200, 80); back.setPosition(40, 50); // Do not forget to add actors to the stage or we wouldn't see anything. stage.addActor(back); stage.addActor(credits); }
From source file:es.danirod.jddprototype.game.controlador.LoadingScreen.java
License:Open Source License
public LoadingScreen(es.danirod.jddprototype.game.controlador.MainGame game) { super(game);//from ww w. j ava2s. co m // Set up the stage and the skin. See GameOverScreen for more comments on this. stage = new Stage(new FitViewport(640, 360)); skin = new Skin(Gdx.files.internal("skin/uiskin.json")); // Create some loading text using this skin file and position it on screen. loading = new Label("Cargando...", skin); //loading.setPosition(320 - loading.getWidth() / 2, 180 - loading.getHeight() / 2); loading.setPosition(250, 180 - loading.getHeight() / 2); stage.addActor(loading); }
From source file:es.danirod.jddprototype.game.vista.CreditsScreen.java
License:Open Source License
public CreditsScreen(final es.danirod.jddprototype.game.controlador.MainGame game) { super(game);// w w w.ja va 2 s .c o m // Create a new stage, as usual. stage = new Stage(new FitViewport(640, 360)); // Load the skin file. The skin file contains information about the skins. It can be // passed to any widget in Scene2D UI to set the style. It just works, amazing. skin = new Skin(Gdx.files.internal("skin/uiskin.json")); // For instance, here you see that I create a new button by telling the label of the // button as well as the skin file. The background image for the button is in the skin // file. back = new TextButton("Atras", skin); /*credits = new Label("Jump Don't Die v1.0.2\n" + "Copyright (C) 2015-2016 Dani Rodriguez\n" + "This game is GNU GPL. Get the code at github.com/danirod/JumpDontDie\n\n" + "Music: \"Long Time Coming\" Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0", skin);*/ credits = new Label("Jump Dont Die.\n" + "Videojuego en 2D para dispositivos moviles Android\n" + "mediante el uso de la libreria libGDX.\n" + "Practica realizada para la asignatura Programacion de Juegos por:\n" + "Jose Francisco Prieto Montes y David Toscano Rodriguez.\n" + "Este juego es una ampliacion de otro que puedes descargar en:\n" + "github.com/danirod/JumpDontDie\n" + "Copyright (C) 2015-2016 Dani Rodriguez\n" + "Music: \"Long Time Coming\" Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0", skin); // Add capture listeners. Capture listeners have one method, changed, that is executed // when the button is pressed or when the user interacts somehow with the widget. They are // cool because they let you execute some code when you press them. back.addCaptureListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Take me to the game screen! game.setScreen(game.menuScreen); } }); // Now I position things on screen. Sorry for making this the hardest part of this screen. // I position things on the screen so that they look centered. This is why I make the // buttons the same size. credits.setPosition(20, 340 - credits.getHeight()); back.setSize(200, 80); back.setPosition(40, 40); // Do not forget to add actors to the stage or we wouldn't see anything. stage.addActor(back); stage.addActor(credits); }
From source file:com.exovum.test.animation.CreditsScreen.java
License:Creative Commons License
public CreditsScreen(final Game game, Screen parentScreen) { this.batch = new SpriteBatch(); this.game = game; this.parent = parentScreen; Gdx.app.log("CreditsScreen", "Creating CreditsScreen"); menuBackground = new Texture(Gdx.files.internal("beach-ocean-sea-bg/transparent-png/full_background.png")); stage = new Stage(new FitViewport(800, 480)); Gdx.input.setInputProcessor(stage);//from w w w .j av a2 s . c o m skin = new Skin(Gdx.files.internal("uiskin.json")); mainTable = new Table(skin); //mainTable.defaults().expand().fill().padBottom(4f).padTop(4f); mainTable.setFillParent(true); baseTable = new Table(skin); baseTable.defaults().expand().fill().padBottom(10f).padTop(10f); Label myHeader = new Label("General", skin, "small-font"); myHeader.setColor(Color.FIREBRICK); myHeader.setAlignment(Align.center); Label myCredits = new Label("Programming and Development\n" + "Caleb Stevenson", skin, "small-font"); myCredits.setColor(Color.BLACK); myCredits.setAlignment(Align.center); Label musicHeader = new Label("Music", skin, "small-font"); musicHeader.setColor(Color.FIREBRICK); musicHeader.setAlignment(Align.center); Label musicCredits = new Label("\"Capre Diem\", \"Hidden Past\", \"Pixel Peeker Polka - slower\"\n" + "Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0\n" + "http://creativecommons.org/licenses/by/3.0/", skin, "small-font"); musicCredits.setColor(Color.BLACK); musicCredits.setAlignment(Align.center); Label artHeader = new Label("Artwork", skin, "small-font"); artHeader.setColor(Color.FIREBRICK); artHeader.setAlignment(Align.center); Label artCredits = new Label("Background and Tree Sprites\n" + "http://bevouliin.com\nopengameart.org", skin, "small-font"); artCredits.setColor(Color.BLACK); artCredits.setAlignment(Align.center); TextButton exitButton = new TextButton("Back to Menu", skin, "small-font"); Table buttonTable = new Table(skin); baseTable.add(myHeader).row(); baseTable.add(myCredits).row(); baseTable.add(musicHeader).row(); baseTable.add(musicCredits).row(); baseTable.add(artHeader).row(); baseTable.add(artCredits).row(); baseTable.add(buttonTable); //menuTable.setBackground("console2"); // Set the color of the BACKGROUND on the buttons Color buttonColor = Color.SKY; exitButton.setColor(buttonColor); // Set the color of the TEXT on the buttons exitButton.getLabel().setColor(new Color(0.91f, 0.91f, 0.91f, 1)); buttonTable.defaults().expand().fill().padBottom(4f).padTop(2f); buttonTable.add(exitButton).width(180f).height(60f); //buttonTable.padTop(20f).padBottom(20f); buttonTable.left(); // Add baseTable containing buttonTable to the next row of mainTable //mainTable.add(buttonTable); mainTable.add(baseTable); // Add mainTable to the stage stage.addActor(mainTable); exitButton.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { Gdx.app.log("CreditsScreen", "Exiting to main menu"); //game.setScreen(new AnimatorMenuScreen(game)); //game.setScreen(parent); //((Game) Gdx.app.getApplicationListener()).setScreen(parent); ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game)); } }); //Use an InputMultiplexer so that the Stage and keyDown input processors can both be used InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(stage); multiplexer.addProcessor(new InputAdapter() { // If the back key is pressed, go to main menu // This also handles the Android 'back' button @Override public boolean keyDown(int keycode) { if (keycode == Input.Keys.BACK) { // Handle the back button Gdx.app.log("CreditsScreen", "KeyDown: BACK pressed"); //AnimatorMenuScreen newMenu = new AnimatorMenuScreen(batch, game); //game.setScreen(newMenu); //game.setScreen(parent); //((Game) Gdx.app.getApplicationListener()).setScreen(parent); ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game)); return true; } return false; } }); Gdx.input.setInputProcessor(multiplexer); }
From source file:es.danirod.jumpdontdie.game.GameOverScreen.java
License:Open Source License
public GameOverScreen(final MainGame game) { super(game);// w w w.ja v a2 s .co m // Create a new stage, as usual. stage = new Stage(new FitViewport(640, 360)); // Load the skin file. The skin file contains information about the skins. It can be // passed to any widget in Scene2D UI to set the style. It just works, amazing. skin = new Skin(Gdx.files.internal("skin/uiskin.json")); // For instance, here you see that I create a new button by telling the label of the // button as well as the skin file. The background image for the button is in the skin // file. retry = new TextButton("Retry", skin); menu = new TextButton("Menu", skin); // Also, create an image. Images are actors that only display some texture. Useful if you // want to display a texture in a Scene2D based screen but you don't want to rewrite code. gameover = new Image(game.getManager().get("gameover.png", Texture.class)); // Add capture listeners. Capture listeners have one method, changed, that is executed // when the button is pressed or when the user interacts somehow with the widget. They are // cool because they let you execute some code when you press them. retry.addCaptureListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Here I go to the game screen again. game.setScreen(game.gameScreen); } }); menu.addCaptureListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // And here I go to the menu screen. game.setScreen(game.menuScreen); } }); // Now I position things on screen. Sorry for making this the hardest part of this screen. // I position things on the screen so that they look centered. This is why I make the // buttons the same size. gameover.setPosition(320 - gameover.getWidth() / 2, 320 - gameover.getHeight()); retry.setSize(200, 80); menu.setSize(200, 80); retry.setPosition(60, 50); menu.setPosition(380, 50); // Do not forget to add actors to the stage or we wouldn't see anything. stage.addActor(retry); stage.addActor(gameover); stage.addActor(menu); }
From source file:es.danirod.jumpdontdie.scene2d.Scene2DScreen.java
License:Open Source License
@Override public void show() { // Create a new stage. stage = new Stage(new FitViewport(640, 400)); // Load the actors. player = new PlayerActor(playerTexture); spikes = new SpikeActor(spikeRegion, 2100, 100, 500); player.setPosition(20, 100);/*from ww w .j av a 2s . c om*/ // Add the actors to the screen. They won't be visible if you don't add them. stage.addActor(player); stage.addActor(spikes); }
From source file:halive.shootinoutside.menu.MainMenu.java
private void init() { float h = Gdx.graphics.getHeight(); float w = Gdx.graphics.getWidth(); stage = new Stage(new FitViewport(w, h)); skin = new Skin(Gdx.files.internal(SKIN_PATH)); Table mainTable = new Table(skin); mainTable.setColor(Color.DARK_GRAY); Image logo = new Image(new Texture(Gdx.files.internal(LOGO_PATH))); Button joinGameButton = new TextButton("Join Game", skin); Button hostGameButton = new TextButton("Host Game", skin); Button mapEditorButton = new TextButton("Map Editor", skin); Button aboutGameButton = new TextButton("About", skin); Button exitButton = new TextButton("Quit Game", skin); joinGameButton.addListener(new ClickHandler() { @Override/* w ww. j a v a 2 s. c om*/ public void onClicked(InputEvent evt, float x, float y) { joinGameClicked(evt, x, y); } }); hostGameButton.addListener(new ClickHandler() { @Override public void onClicked(InputEvent evt, float x, float y) { hostGameClicked(evt, x, y); } }); mapEditorButton.addListener(new ClickHandler() { @Override public void onClicked(InputEvent evt, float x, float y) { editorClicked(evt, x, y); } }); aboutGameButton.addListener(new ClickHandler() { @Override public void onClicked(InputEvent evt, float x, float y) { showAboutDialog(); } }); exitButton.addListener(new ClickHandler() { @Override public void onClicked(InputEvent evt, float x, float y) { Gdx.app.exit(); } }); joinButton = joinGameButton; hostButton = hostGameButton; editorButton = mapEditorButton; mainTable.add(logo).padBottom(PADDING_BOTTOM).row(); Button[] buttons = { joinGameButton, hostGameButton, editorButton, aboutGameButton, exitButton }; for (int i = 0; i < buttons.length; i++) { mainTable.add(buttons[i]).size(BUTTON_WIDTH, BUTTON_HEIGHT).padBottom(PADDING_BOTTOM).row(); } mainTable.setFillParent(true); stage.addActor(mainTable); Gdx.input.setInputProcessor(stage); }
From source file:es.danirod.jddprototype.game.GameOverScreen.java
License:Open Source License
public GameOverScreen(final es.danirod.jddprototype.game.MainGame game) { super(game);//from www . ja v a 2 s . co m // Create a new stage, as usual. stage = new Stage(new FitViewport(640, 360)); // Load the skin file. The skin file contains information about the skins. It can be // passed to any widget in Scene2D UI to set the style. It just works, amazing. skin = new Skin(Gdx.files.internal("skin/uiskin.json")); // For instance, here you see that I create a new button by telling the label of the // button as well as the skin file. The background image for the button is in the skin // file. retry = new TextButton("Retry", skin); menu = new TextButton("Menu", skin); // Also, create an image. Images are actors that only display some texture. Useful if you // want to display a texture in a Scene2D based screen but you don't want to rewrite code. gameover = new Image(game.getManager().get("gameover.png", Texture.class)); // Add capture listeners. Capture listeners have one method, changed, that is executed // when the button is pressed or when the user interacts somehow with the widget. They are // cool because they let you execute some code when you press them. retry.addCaptureListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Here I go to the game screen again. game.setScreen(game.gameScreen); } }); menu.addCaptureListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // And here I go to the menu screen. game.setScreen(game.menuScreen); } }); // Now I position things on screen. Sorry for making this the hardest part of this screen. // I position things on the screen so that they look centered. This is why I make the // buttons the same size. gameover.setPosition(320 - gameover.getWidth() / 2, 320 - gameover.getHeight()); retry.setSize(200, 80); menu.setSize(200, 80); retry.setPosition(60, 50); menu.setPosition(380, 50); // Do not forget to add actors to the stage or we wouldn't see anything. stage.addActor(retry); stage.addActor(gameover); stage.addActor(menu); }
From source file:es.danirod.jddprototype.scene2d.Scene2DScreen.java
License:Open Source License
@Override public void show() { // Create a new stage. stage = new Stage(new FitViewport(640, 400)); // Load the actors. player = new PlayerActor(playerTexture); spikes = new es.danirod.jddprototype.scene2d.SpikeActor(spikeRegion, 2100, 100, 500); player.setPosition(20, 100);/*ww w.j a v a 2 s. co m*/ // Add the actors to the screen. They won't be visible if you don't add them. stage.addActor(player); stage.addActor(spikes); }