我正在制作一个应用程序来帮助我记住我正在学习的一些泰语单词。
但是我无法正确渲染文本。
我用这个例子来创建一个基本场景。这就是我到目前为止所拥有的。
public class ThaiWords extends ApplicationAdapter {
OrthographicCamera cam;
SpriteBatch batch;
BitmapFont thaiFont;
@Override
public void create () {
FreeTypeFontGenerator generator;
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 18;
parameter.characters = "ก";
generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/garuda.ttf"));
thaiFont = generator.generateFont(parameter);
generator.dispose();
batch = new SpriteBatch();
cam = new OrthographicCamera();
cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.update();
}
@Override
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(cam.combined);
batch.begin();
thaiFont.draw(batch, "ก", 0, 66);
batch.end();
}
@Override
public void resize (int width, int height) {
cam.setToOrtho(false, width, height);
}
}
为了测试,我只想显示“ก”字符。上面的代码产生一个“?” 象征。
我直接从libGDX 目录下载了 garuda.tff 字体。
我真的不确定我错过了什么!我什至尝试在运行时生成位图,但产生了一个空白屏幕。
任何建议都会很棒!
编辑:我在 Android Studio 上注意到,当我关闭并重新打开项目时,实际代码从“ก”变为“?”。这可能是一个编码问题,但我不知道如何解决它。