Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In general you don't get sharp text because you are designing your game for a certain resolution and when you move to a different device, Libgdx scales everything to match the new resolution. Even with linear filtering scaling is bad on text because round corners are easily distorted. In a perfect world you would create the content dynamically at runtime according to the number of pixels available to you and not a single automatic scale would be used.</p> <p>This is the approach I'm using: Building everything for small screen (480 x 320), and when you open it on a bigger resolution, I load the BitmapFont with a higher size and apply and inverse scale to the one that Libgdx will later do automatically. </p> <p>Here's an example to make things clearer:</p> <pre><code> public static float SCALE; public static final int VIRTUAL_WIDTH = 320; public static final int VIRTUAL_HEIGHT = 480; public void loadFont(){ // how much bigger is the real device screen, compared to the defined viewport Screen.SCALE = 1.0f * Gdx.graphics.getWidth() / Screen.VIRTUAL_WIDTH ; // prevents unwanted downscale on devices with resolution SMALLER than 320x480 if (Screen.SCALE&lt;1) Screen.SCALE = 1; FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/Roboto-Regular.ttf")); // 12 is the size i want to give for the font on all devices // bigger font textures = better results labelFont = generator.generateFont((int) (12 * SCALE)); // aplly the inverse scale of what Libgdx will do at runtime labelFont.setScale((float) (1.0 / SCALE)); // the resulting font scale is: 1.0 / SCALE * SCALE = 1 //Apply Linear filtering; best choice to keep everything looking sharp labelFont.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload