我正在尝试在我的初始屏幕上预加载大量 TTF 和 OFT 字体,该屏幕还实现了带有纹理的加载栏。
我的想法是,我预加载一组具有设定大小的字体,然后字体管理器在准备好使用时检索字体。
但是在任何地方都没有关于如何使用它的文档。
我试试下面的代码:
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
);
我收到以下错误:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: No loader for type: FreetypeFontLoader
最佳答案
您需要先在 AssetManager
上设置加载器。参见 this test一个工作示例。
// 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));
关于java - 将 FreeType 字体传递给 LibGDX 中的 Assets 加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24925940/