LIBGDX Asset manager load true type font

Viewed 1176

We are trying to load a true type font with the asset manager in a libgdx project. We followed striclty the wiki entry . However, we get the exception

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: basicfont.ttf

with the following code

 // First, let's define the params and then load our smaller font
    FreetypeFontLoader.FreeTypeFontLoaderParameter parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
    parameter.fontFileName = "basicfont.ttf";
    parameter.fontParameters.size = 10;
    game.manager.load("font.ttf", BitmapFont.class, parameter);
    game.manager.finishLoading();

We already loaded the font without the asset manager. Moreover, we also read this link and followed the instruction, which did not solve the problem.

2 Answers
String path="basicfont.ttf";     //can be inside nested folder
String fileName = "font.ttf" ;   // it can be any name with extension, will use to load and retrieve

Load in this way :

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

FreetypeFontLoader.FreeTypeFontLoaderParameter parms = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
parms.fontFileName = path;    // path of .ttf file where that exist 
parms.fontParameters.size = 10;
manager.load(fileName, BitmapFont.class, parms);   // fileName with extension, sameName will use to get from manager

manager.finishLoading();  //or use update() inside render() method

Android file-system is case sensitive.

parameter.fontFileName = "basicfont.ttf";
game.manager.load("font.ttf", BitmapFont.class, parameter);

I think you should use the same name for font in the load method

game.manager.load("basicfont.ttf", BitmapFont.class, parameter);
Related