【发布时间】:2013-12-23 20:50:57
【问题描述】:
我在这里关注答案:How get a string width in Libgdx?
我遇到的问题是 getBounds 似乎没有恢复到正确的宽度。我下面的代码应该在字符串末尾放置点,但是您可以看到一些文本中的点渗出。如何获得正确的文本宽度?
for (HighScore s : this.scoresData){
font.draw(batch, s.name, x, y);
TextBounds nameBounds = font.getBounds(s.name);
font.draw(batch, s.value, (float) (KineticAssaultMain.WIDTH / 1.5f), y);
for (float i = (nameBounds.width + x); i < ((float)Screen.WIDTH / 1.5f);){
TextBounds dot = font.draw(batch, ".", i, y);
i += dot.width;
}
// go to the next line
y -= 32;
}
【问题讨论】:
-
似乎“-”和数字是问题所在,好像它们的特定界限是错误的,而且它们看起来肯定像更大的字体。
-
奇数。您是否在所有字体中都遇到了这个问题,或者只是这个特定的字体?
-
很奇怪。我使用了 hiero 字体编辑器,所以我认为字体可以很好地与 LibGDX 的 TextBounds 配合使用。这是我使用的唯一字体。