Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx font height

Tags:

java

fonts

libgdx

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.

like image 959
Dragomirus Avatar asked Feb 26 '26 07:02

Dragomirus


1 Answers

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;
like image 107
Abhishek Aryan Avatar answered Mar 01 '26 18:03

Abhishek Aryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!