我使用libgdx assetmanager加载资产。只加载图像和声音/音乐时,它听起来不错。但是在加载.otf字体时我遇到了问题。游戏退出,而资产管理员正在进行中。
这里是代码: Java文件AssetsManager.java
assetManager = new AssetManager();
// set the loaders for the generator and the fonts themselves
FileHandleResolver resolver = new InternalFileHandleResolver();
assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
assetManager.setLoader(BitmapFont.class, ".otf", new FreetypeFontLoader(resolver));
// load to fonts via the generator (implicitely done by the FreetypeFontLoader).
// Note: you MUST specify a FreetypeFontGenerator defining the ttf font file name and the size
// of the font to be generated. The names of the fonts are arbitrary and are not pointing
// to a file on disk!
FreetypeFontLoader.FreeTypeFontLoaderParameter freeTypeFontLoaderParameterScore = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
freeTypeFontLoaderParameterScore.fontFileName = Constants.FONT_DEFAULT;
freeTypeFontLoaderParameterScore.fontParameters.size = Constants.XLG_FONT_SIZE;
assetManager.load("defaultScore.otf", BitmapFont.class, freeTypeFontLoaderParameterScore);
FreetypeFontLoader.FreeTypeFontLoaderParameter freeTypeFontLoaderParameterScoreShadow = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
freeTypeFontLoaderParameterScoreShadow.fontFileName = Constants.FONT_DEFAULT;
freeTypeFontLoaderParameterScoreShadow.fontParameters.size = Constants.XLG_FONT_SIZE;
assetManager.load("defaultScoreShadow.otf", BitmapFont.class, freeTypeFontLoaderParameterScoreShadow);
FreetypeFontLoader.FreeTypeFontLoaderParameter freeTypeFontLoaderParameterElapsedTime = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
freeTypeFontLoaderParameterElapsedTime.fontFileName = Constants.FONT_DEFAULT;
freeTypeFontLoaderParameterElapsedTime.fontParameters.size = Constants.MD_FONT_SIZE;
assetManager.load("defaultElapsedTime.otf", BitmapFont.class, freeTypeFontLoaderParameterElapsedTime);
FreetypeFontLoader.FreeTypeFontLoaderParameter freeTypeFontLoaderParameterElapsedTimeShadow = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
freeTypeFontLoaderParameterElapsedTimeShadow.fontFileName = Constants.FONT_DEFAULT;
freeTypeFontLoaderParameterElapsedTimeShadow.fontParameters.size = Constants.MD_FONT_SIZE;
assetManager.load("defaultElapsedTimeShadow.otf", BitmapFont.class, freeTypeFontLoaderParameterElapsedTimeShadow);
Mygame.java
@Override
public void create () {
AssetsManager.getInstance().loadAssets();
setScreen(new SplashScreen());
}
@Override
public void dispose() {
super.dispose();
AssetsManager.getInstance().dispose();
AudioManager.dispose();
Gdx.app.log("STATUS", "DISPOSING");
}
@Override
public void render() {
super.render();
if (finishedLoadingSplash == false){
if (AssetsManager.getInstance().update()){
finishedLoadingSplash = true;
AudioManager.getInstance().init();
setScreen(new GameScreen());
}
}
}
在上面的代码中,assetmanager从.otf文件加载4位图。 当资产管理员正在进行时,游戏突然退出。
但是如果我删除了一些代码,那么资产管理员只需加载1或2 bitmapfont或者如果我改变字体(字体文件大小是136kb并且我用40kb以下更改字体),游戏很好不会突然退出。我弄错了吗?感谢