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 match; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import java.awt.Point; /** * * @author Martin */ public class GameText { private Point position; private String text; private int lifeTime; private BitmapFont font; /** * initializes GameText with the given parameters * @param text * @param position */ public GameText(String text, Point position) { //initialize fonts try { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/MunroSmall.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 30; font = generator.generateFont(parameter); // font size 12 pixels font.setColor(Color.BLACK); generator.dispose(); // don't forget to dispose to avoid memory leaks! } catch (Exception e) { } this.text = text; this.position = position; this.lifeTime = -1; } public GameText(String text, Point position, int lifeTime) { //initialize fonts try { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/MunroSmall.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 30; font = generator.generateFont(parameter); // font size 12 pixels font.setColor(Color.BLACK); generator.dispose(); // don't forget to dispose to avoid memory leaks! } catch (Exception e) { } this.text = text; this.position = position; this.lifeTime = lifeTime; } public int getLifeTime() { return this.lifeTime; } public void setLifeTime(int lifeTime) { this.lifeTime = lifeTime; } public void reduceLifeTime() { if (this.lifeTime > 0) this.lifeTime--; } public BitmapFont getFont() { return this.font; } public void setFont(BitmapFont font) { this.font = font; } public String getText() { return this.text; } public Point getPosition() { return this.position; } public void setPosition(Point position) { this.position = position; } }