10
\$\begingroup\$

I download newest libgdx version 1.6 and i cant solve problem with center my BitmapFont text. Earlier in version 1.54 i used getBounds() method to find out width of text.

Share your solutions, thanks

\$\endgroup\$
2
14
\$\begingroup\$

There was a post explaining the changes, but is not easy to find. The link was on the 1.5.6 release changelog: http://www.badlogicgames.com/wordpress/?p=3666

And the link about changes in fonts was: http://www.badlogicgames.com/wordpress/?p=3658

private static GlyphLayout glyphLayout = new GlyphLayout();
private BitmapFont fontA = new BitmapFont(), fontB = new BitmapFont();

// Set text and font each time you want to calculate bounds.
glyphLayout.setText(fontA, "my string");
fontA.draw(batch, glyphLayout, x + glyphLayout.width / 3, y + glyphLayout.height / 3);
y += glyphLayout.height;

glyphLayout.setText(fontB, "different font");
fontB.draw(batch, glyphLayout, x + glyphLayout.width / 3, y + glyphLayout.height / 3);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.