i'd like to use the asset manager in combination with the FreeTypeFontGenerator.
I dont want to load fnt files cause they display differently on different screenresolutions. So what i do currently is generating my fonts on the fly in every actor or screen. Now i think its best to generate the fonts once when the game is started and load them into the asset manager. But the AssetManager seems to need a filename with the BitmapFont.class parameter. What i want to do is generate 5 different bitmapfonts and and load those BitmapFonts into the assetmanager, so i have all my ressources in one place, and can reuse them. I could just create those BitmapFonts, save them in a list, and give the list to every actor or screen, just like i do with the assetmanager i manage my textures and audio with. But it would be more elegant to have everything in one place, the asset manager.
So, is there a way to load BitmapFonts created with FreeTypeFontGenerator into the assetmanager?
Here you can read about how to supply your own
AssetLoader
.You would have to implement either a
SynchronousAssetLoader
or anAsynchronousAssetLoader
. Those Would get the file to a free type font. With that you can use the generator to generate your desiredBitmapFont
. Since you want to use the asset manager, you have to overwrite the default loader for bitmap fonts like this:Via
AssetLoaderParameters
you could supply further information to your loader, like the font size.The following code is untested, but might work:
UPDATE:
This is no longer necessary, the gdx-freetype extension now has loaders for freetype fonts itself!