【发布时间】:2015-08-29 19:28:43
【问题描述】:
如何获取 BitmapFont 文本的总宽度?
font.draw(batch, text ,Gdx.graphics.getWidth() / 2 - /* text width */ /2,450);
【问题讨论】:
如何获取 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 中使用该值。
【讨论】: