我使用bitmapfont loader和truetypefontparam来加载带有AssetManager的字体,同时启动画面淡入/淡出。加载字体时,淡入淡出屏幕会消失。在AssetManager中加载字体时,主线程被阻止。我通过在启动画面的更新方法中在控制台中打印内容来确认这一点。不加载字体时,此问题已得到修复。我会展示我的代码,我做错了什么?对不起,我的英语不好。
public void loadFonts() {
FreeTypeFontGenerator.setMaxTextureSize(FreeTypeFontGenerator.NO_MAXIMUM);
FileHandleResolver resolver = new InternalFileHandleResolver();
Game.assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
Game.assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
FreetypeFontLoader.FreeTypeFontLoaderParameter parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
parameter.fontParameters.magFilter = Texture.TextureFilter.MipMapLinearNearest;
parameter.fontParameters.minFilter = Texture.TextureFilter.Linear;
parameter.fontFileName = "fonts/score.ttf";
parameter.fontParameters.size = 200;
parameter.fontParameters.color = new Color(1, 1, 1, 1);
Game.assetManager.load("score.ttf", BitmapFont.class, parameter);
parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
parameter.fontFileName = "fonts/score.ttf";
parameter.fontParameters.size = 100;
parameter.fontParameters.color = new Color(1, 1, 1, 1);
Game.assetManager.load("touchToStart.ttf", BitmapFont.class, parameter);
parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
parameter.fontFileName = "fonts/octo.ttf";
parameter.fontParameters.size = 100;
parameter.fontParameters.color = new Color(1, 1, 1, 1);
Game.assetManager.load("highScore.ttf", BitmapFont.class, parameter);
parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
parameter.fontFileName = "fonts/octo.ttf";
parameter.fontParameters.size = 222;
parameter.fontParameters.color = new Color(1, 1, 1, 1);
Game.assetManager.load("popupMenu.ttf", BitmapFont.class, parameter);
parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
parameter.fontFileName = "fonts/octo.ttf";
parameter.fontParameters.size = 200;
parameter.fontParameters.color = new Color(1, 1, 1, 1);
Game.assetManager.load("gameOver.ttf", BitmapFont.class, parameter);
}
-
private void loadAssets() {
FontManager.getFontManager().loadFonts(); //Load fonts is the method above
Game.assetManager.load("assets.txt", TextureAtlas.class);
Game.assetManager.load("assets2.txt", TextureAtlas.class);
Game.assetManager.load("sound/tap.mp3", Sound.class);
Game.assetManager.load("sound/point.mp3", Sound.class);
Game.assetManager.load("sound/death.mp3", Sound.class);
}