【问题标题】:LibGDX getBounds not returning correct widthLibGDX getBounds 没有返回正确的宽度
【发布时间】: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 配合使用。这是我使用的唯一字体。

标签: java libgdx


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-12-06
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多