gpt4 book ai didi

java - LibGDX getBounds 未返回正确的宽度

转载 作者:行者123 更新时间:2023-11-30 04:05:50 26 4
gpt4 key购买 nike

我在这里关注答案:How get a string width in Libgdx?

我遇到的问题是 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;
}

最佳答案

调用另一个 BitmapFont 方法后,从 getBounds 返回的 TextBounds 不保证有效。 TextBounds 实例在内部重用以避免分配。这是一个不幸的陷阱,但它是 libgdx 避免 GC 的结果。

关于java - LibGDX getBounds 未返回正确的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20750984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com