0
votes

I use an OrthographicCamera set to 720 by 1280 and then set it's combined matrix as the projection matrix in my SpriteBatch. I then generate a BitmapFont using the FreeTypeFontGenerator and use it to render text.

OrthographicCamera camera = new OrthographicCamera();
camera.setToOrtho(false, 720, 1280);
SpriteBatch batch = new SpriteBatch();
batch.setProjectionMatrix(camera.combined);

This is the output:

This is the output

As you can see the fonts look very distorted and the only way I found to fix it is by removing the line where I set the projection matrix in my SpriteBatch.

batch.setProjectionMatrix(camera.combined);

I put this as an issue on the lib GDX github page, but I was told this is not because of Lib GDX. I need to use this projection matrix so that I can develop my application in one resolution and have it scale to fit any screen. Is there a way to render text without encountering this problems?

1

1 Answers

0
votes

Use a pixel perfect projection, by using ScreenViewport. Then use Table to layout your GUI, including its labels. This way you can also support multiple aspect ratio or even use a different layout depending on the aspect ratio.

If you want to support a wide range of resolution then you will need to provide different assets depending on the resolution. Depending on the file size you might want to use different build flavors or use ResolutionFileHandleResolver. Alternatively you can use the freetype extension to generate the correct font for the device, but be aware that that might result in additional render calls which can affect performance.

Note that all of this only applies for your GUI. For you game logic you obviously use the coordinate system that makes most sense for that (e.g. meters), with a separate camera.