search

Home  >  Q&A  >  body text

android - libGDX 显示ttf字体出错

libGDX版本1.6.1

使用ttf文件显示字体时显示不正确

    private BitmapFont mFont;

    private FreeTypeFontGenerator mFontGenerator;

    private FreeTypeFontGenerator.FreeTypeBitmapFontData mFontData;

    private FreeTypeFontGenerator.FreeTypeFontParameter mFontParameter;

        //初始化文字对象
        mFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));

        mFontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        mFontParameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS+"hello 你好吗";
        mFontParameter.size = 40;
        mFontParameter.color = Color.RED;

        mFont = mFontGenerator.generateFont(mFontParameter);
@Override
public void render() {
    Gdx.gl.glClearColor(1, 1, 1, 1);    //设置背景白色
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    mBatch.begin();

    //文字
    mFont.draw(mBatch,"hello 你好吗",450,100);

    mBatch.end();

}
大家讲道理大家讲道理2772 days ago512

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 18:03:00

    Finally, I found that there was a problem with the ttf file. I changed a few ttf files before it was displayed normally. I recommend a ttf website to everyone. It feels good http://font.chinaz.com/

    reply
    0
  • Cancelreply