# Two BitmapFonts from one .ttf font using AssetManager

I'm trying to start using AssetManager in my game. Previously I used to generate two BitmapFonts (bigger and smaller) from my .ttf file and it worked well. Here's how it looked in the code:

FreeTypeFontGenerator generatorRoboto = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Roboto-Regular.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter params = new FreeTypeFontGenerator.FreeTypeFontParameter();
params.size = 80;
BitmapFont robotoFont = generatorRoboto.generateFont(params);
robotoFont.getData().setScale(0.5f);
robotoFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
params.size = 40;
BitmapFont smallerFont = generatorRoboto.generateFont(params);
smallerFont.getData().setScale(0.6f);
smallerFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear,
Texture.TextureFilter.Linear);


Then I add it to skin and use it.

skin.add("roboto-regular-font", robotoFont, BitmapFont.class);


It works well, but now I'm trying to use it with AssetManager (according to documentation):

FreeTypeFontLoaderParameter robotoFontLP = new FreeTypeFontLoaderParameter();
robotoFontLP.fontFileName = "fonts/Roboto-Regular.ttf";
robotoFontLP.fontParameters.size = 80;

BitmapFont robotoFontBig = manager.get("fonts/Roboto-Regular.ttf", BitmapFont.class);
robotoFontBig.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
robotoFontBig.getData().setScale(0.5f);
BitmapFont robotoFontSmall = manager.get("fonts/Roboto-Regular.ttf", BitmapFont.class);
robotoFontSmall.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
robotoFontSmall.getData().setScale(0.15f);



But it doesn't work, LibGDX treat them as the same font. What am I doing wrong?

I believe this could be an issue with the AssetManager as it uses an objectMap which maps loaded objects to the string used to load them. In this case you're loading the font and the assetManager is storing it in it's objectMap under the key "fonts/Roboto-Regular.ttf", then when you load your font again with second set of parameters the previous font is overwritten.

I found this workaround from this page.

One solution would be to pass an id as the name, and also have parameters that get passed to the TTF loader that actually contains the filename.

This example shows how to use the parameter file to define font file name leaving the name in the load method to be used purely as a key. Adapted from the libgdx ttf test found here

    FreeTypeFontLoaderParameter robotoFontBigParam = new FreeTypeFontLoaderParameter();
size1Params.fontFileName = "fonts/Roboto-Regular.ttf";
size1Params.fontParameters.size = 40;
manager.load("size40.ttf", BitmapFont.class, robotoFontBigParam );