# LibGDX . draw multiline text

I am trying to write a big text using BitmapFont in libGDX . But it shows on one line and the user can see only the first part of the text . How can I make that bitmapFont made new line automatically and show whole text on the screen ?

• So basically you are looking for a "Word wrap" option. – Kromster Aug 22 '14 at 8:10
• yes, something like that – Vahe Muradyan Aug 22 '14 at 8:13

You should use BitmapFont.drawWrapped.

public BitmapFont.TextBounds drawWrapped(Batch batch,
java.lang.CharSequence str,
float x,
float y,
float wrapWidth)


All you need to do is set the wrapWidth variable as the maximum length of the line. In your case, this works better than BitmapFont.drawMultiLine because it automatically wraps rather than solely responding to \n.

Write multiline text in LibGdx

To write a multiline text with bitmapFont just use this following code-

String completeText= "In this text there are multi lines\n.To write this race in your game
\n you have to write in proper manner.
\nYou have to make the text look better .";

font.drawMultiLine(
batch,
completeText,
x,y,width,heigth, HAlignment.LEFT);


Isn't is simple to write a multiline text.