LibGDX sprite batch font bad scale rendering

Viewed 3013

I am facing an issue while trying to put a text/dialog system in my game project. When I create a font and call the draw method on it passing the camera updated spriteBatch, each pixel of the font has the same dimension of one sprite.

I get the following render:

font draw scale issue

What you can see on the picture is the top of the "h" of "hello" with each pixel oversized. The same camera is used to render the tiles/sprites.

The effect I want to achieve is similar to this:

Elliot quest example

Here is the code:

    // 15 * 12 tile size
    camera = new OrthographicCamera(Const.VIEWPORT_WIDTH, Const.VIEWPORT_HEIGHT);
    BitmapFont font = new BitmapFont(Gdx.files.internal("data/fonts/myfont.fnt"));

    // ....

    // p => player position   
    camera.position.x = p.getX();
    camera.position.y = p.getY();
    camera.update();

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    font.draw(batch, "hello", p.getX(), p.getY());
    batch.end();

I have tried using font.setScale() with no success.

Does someone know how to achieve this?

2 Answers
Related