2
votes

Does anyone know what is the formula to calculate height of bitmap font with specific size? I know that when I draw a string on a screen I'm creating a rectangle to do that and I want to know what is the height of this rectangle.

1

1 Answers

2
votes

If you're using LibGDX version >= 1.5.6 then you can get height of font by GlyphLayout.

Bitmap font = new BitmapFont();
GlyphLayout layout = new GlyphLayout(); 
layout.setText(font, "meow");
float height = layout.height;  //height of "meow"

but if still you're using LibGDX API < 1.5.6, you can get height by this

float height = font.getBounds("meow").height;