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

2 Answers 2

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
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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .