1

I'm trying to draw simple text with libGDX on the screen. The thing that I want to consider is the size of the text. I would like to draw score of the player on the screen which i would like it to be big. But even i use the freetype fonts, it's not looking smooth. Here is the code:

    SpriteBatch batch;
    String string;
    FreeTypeFontGenerator generator;
    FreeTypeFontParameter parameter;
    BitmapFont font;

    @Override
    public void create () {
        batch = new SpriteBatch();
        generator = new FreeTypeFontGenerator(Gdx.files.internal("arial.ttf"));
        parameter = new FreeTypeFontParameter();
        parameter.size = 100;
        font = generator.generateFont(parameter);

        string = "0123456";
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        batch.begin();
        font.draw(batch, string, 50, 400);
        batch.end();
    }

Am i on the right path to draw the score or some HUD screen to the viewport? Is there a nicer way or is there a way to do this with the fonts easily? (For starting to learn from scratch?)

EDIT: Here is how it looks like enter image description here

Tolga Şen
  • 289
  • 5
  • 14
  • Need to see a screenshot to know what's wrong. You're getting a bit ahead of yourself though. You need to know what size camera or viewport you're going to use before you can properly pick what font size to use. – Tenfour04 Apr 03 '16 at 00:23
  • I have added a picture with the edit – Tolga Şen Apr 03 '16 at 21:25
  • The answer is here http://stackoverflow.com/questions/14675007/how-to-draw-smooth-text-in-libgdx – Dr Deo Dec 02 '16 at 08:44

1 Answers1

1

Try setting the minFilter and magFilter of FreeTypeFontGeneratorParameter to Linear, like this:

    @Override
    public void create () {
        batch = new SpriteBatch();
        generator = new FreeTypeFontGenerator(Gdx.files.internal("arial.ttf"));
        parameter = new FreeTypeFontParameter();
        parameter.size = 100;
        parameter.minFilter = Texture.TextureFilter.Linear;
        parameter.magFilter = Texture.TextureFilter.Linear;
        font = generator.generateFont(parameter);

        string = "0123456";
    }