【问题标题】:Libgdx how to get the total width of a text? (BitmapFont)Libgdx如何获取文本的总宽度? (位图字体)
【发布时间】:2015-08-29 19:28:43
【问题描述】:

如何获取 BitmapFont 文本的总宽度?

font.draw(batch, text ,Gdx.graphics.getWidth() / 2 - /* text width */ /2,450);

【问题讨论】:

标签: android fonts libgdx


【解决方案1】:

使用GlyphLayout 计算使用特定字体的某些字符串的宽度:

GlyphLayout layout = new GlyphLayout(font, text);
float textWidth = layout.width;

不过,不要把它放在render 方法中。最好在createshow 中计算并存储一次该值,然后在render 中使用该值。

【讨论】:

    猜你喜欢
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    相关资源
    最近更新 更多