1

I need to use glyphlayout so that I can centre the text, but I found if I do the text gets distorted due to the spacing being incorrect.

public SimpleButton(String text, float x, float y, float w, float h, BitmapFont font) {
    pos = new Vector2(x, y);
    this.w = w;
    this.h = h;
    this.text = text;
    this.font = font;
    glyphLayout.setText(font, text);
    hitbox = new Rectangle(x, y - h, w, h);
}

public void render(SpriteBatch batch) {
    font.draw(batch, text, pos.x, pos.y);
}

Like this it displays fine:

enter image description here

But using glyphlayout to draw it the spacing for some reason is different:

public void render(SpriteBatch batch) {
    font.draw(batch, glyphLayout, pos.x, pos.y);
}

enter image description here

Glyphlayout seems to be changing the spacing here, but I couldn't see any options for setting the spacing with it.

Hasen
  • 7,909
  • 17
  • 53
  • 106

0 Answers0