Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx - Placing Bitmap font in center of screen

I am new to Libgdx but with proficient knowledge in Android. I am able to place the texture in center of the screen. But when it comes to bitmapfont with the string "Level 1", I am not able to decide the width of the String and hence I am not able to place it in center of the screen.

Could you please help me to find the width/height of the Bitmapfont which has the string "Level 1"

like image 784
iappmaker Avatar asked Jan 09 '23 15:01

iappmaker


1 Answers

font.getBounds() doesn't work anymore, so the answer should be updated.

You can use the following:

GlyphLayout glyphLayout = new GlyphLayout();
String item = "Example";
glyphLayout.setText(font,item);
float w = glyphLayout.width;

and use w to center with respect to a position

like image 162
Buddy Avatar answered Jan 18 '23 11:01

Buddy