Skip to content
Syed zainul abedin edited this page Apr 11, 2018 · 3 revisions

Mini2Dx has support for TrueTypeFonts through the freetype LibGDX extension.

Note: Due to mini2Dx placing its origin in the top left corner of the screen (LibGDX places its origin on the bottom left), all fonts have to be flipped when loaded.

Loading a font

//Generate a font object for font.ttf at size 40px
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 40;
parameter.flip = true;

//The following settings allow the font to scale smoothly
parameter.magFilter = TextureFilter.Linear;
parameter.minFilter = TextureFilter.Linear;

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));

BitmapFont myFont = generator.generateFont(parameter);
myFont.setUseIntegerPositions(false);

Using the font during rendering

	public void render(Graphics g) {
		//Set the graphics font
		g.setFont(font);
		//Draw using the font
		g.drawString("Hello, world!", 32, 32);
	}

Clone this wiki locally