2013-12-23 38 views
1

在這裏,我的回答如下:How get a string width in Libgdx?LibGDX的getBounds返回不正確的寬度

我遇到的問題是,似乎的getBounds不返回到正確的寬度。我的代碼應該在字符串的末尾放置點,但是您可以看到通過某些文本點出血的點。我如何獲得正確的文字寬度?

enter image description here

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; 
} 
+0

看起來「 - 」和數字是問題,就像他們的特定邊界是錯誤的,他們看起來像是從一個更大的字體。 – Lestat

+0

奇數。你在所有字體中遇到這個問題,還是隻有這個特定的問題? –

+0

很奇怪。我使用了hiero字體編輯器,所以我認爲字體可以很好地與LibGDX的TextBounds配合使用。這是我使用的唯一字體。 – James

回答

2

的TextBounds從返回的getBounds是不能保證調用另一個BitmapFont方法纔有效。 TextBounds實例在內部被重用以避免分配。這是一個不幸的問題,但是是避免GC的libgdx的結果。

相關問題