How to get the total width of a BitmapFont text?
font.draw(batch, text ,Gdx.graphics.getWidth() / 2 - /* text width */ /2,450);
How to get the total width of a BitmapFont text?
font.draw(batch, text ,Gdx.graphics.getWidth() / 2 - /* text width */ /2,450);
Use a GlyphLayout
to calculate the width of some string using a particular font:
GlyphLayout layout = new GlyphLayout(font, text);
float textWidth = layout.width;
Don't put this in the render
method, though. It is a good idea to calculate and store this value once in create
or show
and then just use the value in your render
.