8000 TrueType Fonts · Khazrak/mini2Dx Wiki · GitHub
[go: up one dir, main page]

Skip to content
tomcashman edited this page Feb 24, 2013 · 1 revision

Mini2Dx has support for TrueTypeFonts through the freetype LibGDX extension. However, due to mini2Dx placing its origin in the top left corner of the screen, all fonts loaded will be upside-down when rendered.

Loading a font

//Generate a font object for font.ttf at size 40px
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));
BitmapFont font = generator.generateFont(40, FreeTypeFontGenerator.DEFAULT_CHARS, true);

Setting a font as the Graphics context font

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

Allowing the font to scale smoothly

font.setUseIntegerPositions(false);
font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

Clone this wiki locally

0