How to draw smooth text in libgdx?

前端 未结 10 1282
暖寄归人
暖寄归人 2020-12-01 00:01

I try to draw simple text in my android game on libgdx, but it\'s look sharp. How to make text look smooth in different resolutions? My Code:



        
10条回答
  •  日久生厌
    2020-12-01 00:47

    In scene2d, if you want apply antialiasing to all your labels, put this on constructor of your first screen:

    skin.getFont("default-font").getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    

    This is the first screen in my game:

    ...
    public class MainMenuScreen implements Screen {    
        public MainMenuScreen() {
            ...
            skin.getFont("default-font").getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
        }
    }
    

    Font name is in ui.json file, check for BitmapFont and Label$LabelStyle section:

    "com.badlogic.gdx.graphics.g2d.BitmapFont": {
        "default-font": {
          "file": "default.fnt"
        }
      },
    "com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
        "default": {
          "font": "default-font",
          "fontColor": "white",
        }
      },
    

提交回复
热议问题