1
在這裏,我的回答如下:How get a string width in Libgdx?LibGDX的getBounds返回不正確的寬度
我遇到的問題是,似乎的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;
}
看起來「 - 」和數字是問題,就像他們的特定邊界是錯誤的,他們看起來像是從一個更大的字體。 – Lestat
奇數。你在所有字體中遇到這個問題,還是隻有這個特定的問題? –
很奇怪。我使用了hiero字體編輯器,所以我認爲字體可以很好地與LibGDX的TextBounds配合使用。這是我使用的唯一字體。 – James