3

I'm trying to preload a load of TTF and OFT fonts on my splash screen that also implements a loading bar aling with textures.

The idea is is that I preload a load of fonts with set sizes then the font manager retrieves the font when it's ready to be used.

I found the following class https://github.com/libgdx/libgdx/blob/master/extensions/gdx-freetype/src/com/badlogic/gdx/graphics/g2d/freetype/FreetypeFontLoader.java

But there is no documentation anywhere of how to use it.

I try the following code:

parameter.size = (int)Math.ceil(fontStorage.fontSize);
    FreetypeFontLoader.FreeTypeFontLoaderParameter freeTypeParams = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
    freeTypeParams.fontParameters = parameter;
    freeTypeParams.fontFileName = fontStorage.fontFile;

    GameAssetLoader.getInstance().getAssetManager().load(
            fontStorage.fontFile,
            FreetypeFontLoader.class,
            (AssetLoaderParameters)freeTypeParams
    );

I get the following error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: No loader for type: FreetypeFontLoader
Oliver Dixon
  • 7,012
  • 5
  • 61
  • 95

1 Answers1

5

You need to set the loaders on the AssetManager first. See this test for a working example.

// set the loaders for the generator and the fonts themselves
FileHandleResolver resolver = new InternalFileHandleResolver();
GameAssetLoader.getInstance().getAssetManager().setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
GameAssetLoader.getInstance().getAssetManager().setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
noone
  • 19,520
  • 5
  • 61
  • 76