LibGDX我的字体不起作用

时间:2018-05-16 17:55:57

标签: android libgdx

我想从网上将我的字体更改为自定义字体,我从此网站下载了Cool Crayon: https://www.dafont.com/dk-cool-crayon.font 我有两个名为Bitmap_0.tga和Bitmap.fnt的文件

我试着用我的知识和谷歌搜索来实现它的代码。

到目前为止,我已经这样做了:

private Skin skin;


Skin font = new Skin(Gdx.files.internal("font/Bitmap.fnt"));

behindTable = new Table(font);
table = new Table(font);

Label heading = new Label(QuizMain.TITLE, font);
TextButton buttonMap = new TextButton("Map", font);

table.add(heading).spaceBottom(100).row();        
table.add(buttonMap).spaceLeft(15);

起初我以为它会起作用,但我一直都会遇到错误,我无法理解如何前进或者我写的东西是错的。

我的logcat

  com.badlogic.gdx.utils.SerializationException: Error reading file: font/Bitmap.fnt

PS。我知道我的桌子和所有“幕后”的东西都有效:)

感谢。

1 个答案:

答案 0 :(得分:0)

你的错是在这里:

Skin font = new Skin(Gdx.files.internal("font/Bitmap.fnt"));

您尝试从字体文件生成皮肤。 Click here了解皮肤是如何工作的。

要从.fnt文件创建BitmapFont,您必须使用与此类似的内容:

BitmapFont font = new BitmapFont(Gdx.files.internal("font/Bitmap.fnt"));