Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package scenes; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.circle.game.Config; import networking.GameClient; /** * * @author <a href="mailto:kevin.vanderburg@student.fontys.nl">Kevin van der Burg</a> */ public class SearchGame extends ApplicationAdapter { private Stage stage; //done private TextureAtlas atlas; //done private Skin skin; //done private Table table; // Align all buttons private TextButton cancelButton; private BitmapFont font60; private BitmapFont font25; private BitmapFont font30; private BitmapFont font30Fade; private GlyphLayout layout; private SpriteBatch batch; private FontFade fade; private String map; private String gameMode; private int numberOfPlayers; String dots = ""; public SearchGame(String map, String gameMode, int numberOfPlayers) { this.map = map; this.gameMode = gameMode; this.numberOfPlayers = numberOfPlayers; create(); } @Override public void create() { layout = new GlyphLayout(); batch = new SpriteBatch(); //initialize fonts FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/MunroSmall.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 60; font60 = generator.generateFont(parameter); // font size 12 pixels font60.setColor(Color.BLACK); parameter.size = 40; font30 = generator.generateFont(parameter); // font size 12 pixels font30.setColor(0.38f, 0.38f, 0.38f, 1f); font30Fade = generator.generateFont(parameter); // font size 12 pixels font30Fade.setColor(0.38f, 0.38f, 0.38f, 1f); parameter.size = 25; font25 = generator.generateFont(parameter); // font size 12 pixels font25.setColor(Color.BLACK); generator.dispose(); // don't forget to dispose to avoid memory leaks! fade = new FontFade(font30Fade); //prepare buttons stage = new Stage(); Gdx.input.setInputProcessor(stage); atlas = new TextureAtlas("ui/buttonPack.pack"); skin = new Skin(atlas); table = new Table(skin); table.setBounds(0, -150, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); final TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); textButtonStyle.downFontColor = new Color(0f, 0.57f, 0.92f, 1f); textButtonStyle.overFontColor = new Color(0f, 0.57f, 1f, 1f); textButtonStyle.font = font30; textButtonStyle.fontColor = Color.BLACK; cancelButton = new TextButton("Cancel", textButtonStyle); cancelButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { GameClient.leaveGames(); Config.page = new GameModeSelect(); } }); cancelButton.pad(20); table.add(cancelButton); stage.addActor(table); GameClient.joinGame(gameMode, map, numberOfPlayers); } @Override public void render() { batch.begin(); //Write Circle layout.setText(font60, "Joining game"); int x = (int) (Gdx.graphics.getWidth() / 2 - layout.width / 2); int y = (int) (Gdx.graphics.getHeight() / 2 + 60); font60.draw(batch, "Joining game", x, y); // //Write entered name layout.setText(font30, "Looking for an Active: " + gameMode); x = (int) (Gdx.graphics.getWidth() / 2 - layout.width / 2); y = (int) (Gdx.graphics.getHeight() / 2 - 30); font30.draw(batch, "Looking for an Active: " + gameMode, x, y); //Write fading text trailer layout.setText(font30, "Looking for an Active: " + gameMode); x = (int) (x + layout.width); y = (int) (Gdx.graphics.getHeight() / 2 - 30); font30Fade.draw(batch, " ...", x, y); fade.update(); batch.end(); stage.act(); stage.draw(); } }