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 ?

  • \$\begingroup\$ So basically you are looking for a "Word wrap" option. \$\endgroup\$ – Kromster Aug 22 '14 at 8:10
  • \$\begingroup\$ yes, something like that \$\endgroup\$ – 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.

| improve this answer | |

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 .";

             x,y,width,heigth, HAlignment.LEFT);

Isn't is simple to write a multiline text.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.