Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Detailing the FreeTypeFont creation process

Before creating you fonts, you need these lines :

FileHandleResolver resolver = new InternalFileHandleResolver(); game.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver)); game.assets.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));

They allow the Asset Manager to load the .ttf file and generate the FreeTypeFont based on the parameters you'll use.

Then you create the parameter :

FreeTypeFontLoaderParameter size1Params = new FreeTypeFontLoaderParameter();

The parameter is composed of the font file ( .ttf) you put in you Asset folder :

size1Params.fontFileName = "Fonts/good times rg.ttf"; 

Then you can to this parameter a filter to have very smooth font :

size1Params.fontParameters.genMipMaps = true; size1Params.fontParameters.minFilter = TextureFilter.Linear; size1Params.fontParameters.magFilter = TextureFilter.Linear; 

And finally, you chose a size for your font :

size1Params.fontParameters.size = Gdx.graphics.getWidth()/18;

Notice that the size is dependant on the screen size, which is all the interest of using FreeTypeFonts. The size of this font relative to the screen size will be the same on every screens.

Then, all that remains is loading the font in the Asset Manager :

game.assets.load("fontMenu.ttf", BitmapFont.class, size1Params);

Notice that you can chose the name you want at this point for your font. In this case I chose "fontMenu.ttf", thus when I'll need that font, I'll do :

game.assets.get("fontMenu.ttf", BitmapFont.class) 

And that's it ! You can create the font of any size you want by this method !