Android studio 使用libgdx崩溃在标签上设置自定义字体

Android studio 使用libgdx崩溃在标签上设置自定义字体,android-studio,fonts,libgdx,load,Android Studio,Fonts,Libgdx,Load,我在加载ttf文件时遇到问题,我的代码: Label migliaLabel; migliaLabel = new Label("label", new Label.LabelStyle(new BitmapFont(Gdx.files.internal("Kalam-Regular.ttf")), Color.MAGENTA)); 文件Kalam-Regular.ttf位于文件夹assets/Kalam-Regular.ttf中 但当我运行游戏时,android studio出错了: 致命异

我在加载ttf文件时遇到问题,我的代码:

Label migliaLabel;
migliaLabel = new Label("label", new Label.LabelStyle(new BitmapFont(Gdx.files.internal("Kalam-Regular.ttf")), Color.MAGENTA));
文件Kalam-Regular.ttf位于文件夹assets/Kalam-Regular.ttf中 但当我运行游戏时,android studio出错了:

致命异常:GL125线程 com.badlogic.gdx.utils.GdxRuntimeException:加载字体文件时出错: Kalam-Regular.ttf 在 com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:665) 在 com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData。(BitmapFont.java:475) 在 com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:114) 在 com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:107) 在com.surfservision.game.GameClass.show(GameClass.java:181)上 在com.badlogic.gdx.Game.setScreen上(Game.java:61) 在com.surfsurvivor.game.SurfClass.create上(SurfClass.java:26) 在 com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254) 在 GLSurfaceView$GLThread.guarderun(GLSurfaceView.java:1505) 位于android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) 原因:com.badlogic.gdx.utils.GdxRuntimeException:无效 衬垫。 在 com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:488) 在 com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData。(BitmapFont.java:475) 在 com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:114) 在 com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:107) 在com.surfservision.game.GameClass.show(GameClass.java:181)上 在com.badlogic.gdx.Game.setScreen上(Game.java:61) 在com.surfsurvivor.game.SurfClass.create上(SurfClass.java:26) 在 com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254) 在 GLSurfaceView$GLThread.guarderun(GLSurfaceView.java:1505) 位于android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)


如何解决此问题?

我使用Hiero解决了此问题,您可以从网站下载并转换文件ttf files.fnt。现在它对我有用了

现在设置字体:

migliaLabel = new Label("label", new Label.LabelStyle(new BitmapFont(Gdx.files.internal("Kalam-Regular.fnt")), Color.MAGENTA));

在处理TTF文件时,LibGDX有一个名为的库,允许您从TTF文件生成
BitmapFont
对象。如何从TTF文件生成字体的示例如下所示:

    /**Initialises the generator using the file location given.*/
    generator = new FreeTypeFontGenerator(Gdx.files.local(fontLocation));
    params = new FreeTypeFontParameter();

    /**Sets the parameters of the object constant for the font, regardless of size.*/
    params.borderWidth = BORDER_WIDTH;
    params.borderColor = Color.BLACK;
    params.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
    params.magFilter = TextureFilter.Nearest;
    params.minFilter = TextureFilter.Nearest;
    params.genMipMaps = true;
    params.size = FONT_SIZE;

    /**Generates the font using the generator object.*/
    font = generator.generateFont(params);