如何获取 BitmapFont 文本的总宽度?
font.draw(batch, text ,Gdx.graphics.getWidth() / 2 - /* text width */ /2,450);
最佳答案
使用 GlyphLayout
使用特定字体计算某些字符串的宽度:
GlyphLayout layout = new GlyphLayout(font, text);
float textWidth = layout.width;
不过,不要将其放入 render
方法中。最好在 create
或 show
中计算并存储该值一次,然后在 render
中使用该值。
关于android - Libgdx如何获取文本的总宽度? (位图字体),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32289925/