Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Irregular font spacing in LibGDX

I am developing this game in LibGDX and I have a BitmapFont that I am using to write the score on the screen. The font comes out with weird spacing and it changes when it moves. How can I fix that? Here are some examples of how the text shows up:

Spacing between E and S

Spacing normal

Spacing between B and E

Here is the code for the font:

generator = new FreeTypeFontGenerator(Gdx.files.internal("font/komika.ttf"));
parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 100;
defaultFont = generator.generateFont(parameter);

Here is the code for the label:

topScoreLabel = new Label(String.valueOf("Best : " + topScore), skin);
topScoreLabel.setColor(Color.RED);
topScoreLabel.setBounds(GAME_WORLD_WIDTH - 30, GAME_WORLD_HEIGHT - 20 * aspectRatio, 25, 20 * aspectRatio);
topScoreLabel.setFontScale(0.05f);
topScoreLabel.setAlignment(Align.right);

I am using such a big font because it should scale well in big screens, which it didn't if I had any smaller. How do I fix this issue?

like image 422
A. Savva Avatar asked Jun 22 '16 12:06

A. Savva


1 Answers

Use font.setUseIntegerPositions(false). It's on by default, because text is typically used with a pixel-perfect camera/viewport and looks less blurry if the sprites are aligned with the screen pixels.

like image 117
Tenfour04 Avatar answered Oct 14 '22 16:10

Tenfour04