3
\$\begingroup\$

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 ?

\$\endgroup\$
  • \$\begingroup\$ So basically you are looking for a "Word wrap" option. \$\endgroup\$ – Kromster says support Monica Aug 22 '14 at 8:10
  • \$\begingroup\$ yes, something like that \$\endgroup\$ – Vahe Muradyan Aug 22 '14 at 8:13
3
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

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.