N
N
Noortvel2015-11-03 20:42:42
Java
Noortvel, 2015-11-03 20:42:42

LibGDX. How to output text correctly?

I dug in the UI documentation, found one display of the Label text, but you can’t change the font in it, only Scale, but it doesn’t look very nice. Actually, how to display text in LibGDX correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Prosto_Bro, 2015-11-04
@Noortvel

Taken from this site

BitmapFont font;
public static final String FONT_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789][_!$%#@|\\/?-+=()*&.;,{}\"´`'<>";
font = TrueTypeFontFactory.createBitmapFont(Gdx.files.internal("font.ttf"), FONT_CHARACTERS, 12.5f, 7.5f, 1.0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
font.setColor(1f, 0f, 0f, 1f);

batch.begin();
font.draw(font, "This is some text", 10, 10);
batch.end();

This is where the ttf fonts are loaded, you can choose any and load it. If you need to download otf then you can use this or
Regarding the function createBitmapFont()and its parameters, you can read in the libgdx documentation.
PS As far as I understand, the project must have the option (when generating) FreeType enabled. For created projects, you need to place the library in the project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question