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.InputAdapter; 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.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.circle.game.Config; /** * * @author <a href="mailto:martin.drost@student.fontys.nl">Martin Dorst</a> */ public class SplashScreen extends ApplicationAdapter { private SpriteBatch batch; private BitmapFont font60; private BitmapFont font30; private GlyphLayout layout; private FontFade fade; public SplashScreen() { create(); } @Override public void create() { layout = new GlyphLayout(); batch = new SpriteBatch(); //initialize fonts FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/MunroSmall.ttf")); FreeTypeFontParameter parameter = new 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); generator.dispose(); // don't forget to dispose to avoid memory leaks! fade = new FontFade(font30); Gdx.input.setInputProcessor(new InputAdapter() { @Override public boolean keyDown(int keyCode) { Config.page = new EnterName(); return true; } }); } @Override public void render() { batch.begin(); //Write Circle layout.setText(font60, "Circle"); int x = (int) (Gdx.graphics.getWidth() / 2 - layout.width / 2); int y = (int) (Gdx.graphics.getHeight() / 2 + 60); font60.draw(batch, "Circle", x, y); //Write instrustions layout.setText(font30, "Press any key to continue"); x = (int) (Gdx.graphics.getWidth() / 2 - layout.width / 2); y = (int) (Gdx.graphics.getHeight() / 2 - 30); font30.draw(batch, "Press any key to continue", x, y); fade.update(); batch.end(); //When the user presses a key he may continue } }