I am developing a game for android using libGDX
. To handle the custom fonts (of different sizes) I am generating them using FreeType to facilitate the varying resolutions on mobile.
I am trying to determine a way to store these generated fonts so they aren't regenerated each time the program launches. It took almost 14 extra seconds to generate 5 fonts (on android using high-end mobile.)
My plan is to generate them once on the user's first launch and store them as .fnt files on the users device, which the application will retrieve upon subsequent runs.
Using the libGDX API
I put the generated fonts in BitmapFont
objects. I was exploring whether I could simply extract the data using the class's own methods and write them to a file. However, such things as getData()
or getString()
proved useless with my amateur skill.
The following code describes my general approach to storing the font as one of libGDX's
BitmapFont
objects:
public static BitmapFont font;
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = (int) (screenW / 6);
font = generator.generateFont(parameter);
generator.dispose();
All I need is to somehow create a file using the data from the BitmapFont, but I cant find a direction to go in.
Ps. This is my first post, so I apologize for my lack of formatting and eloquence.
Solution: Hey everyone, I found a git repo in which there is a very nice solution to this problem, here is the link for anyone that needs it https://github.com/jrenner/gdx-smart-font