6
votes

I am using a BitmapFont to render text the problem is that I decided to use TrueTypeFontFactory.createBitmapFont method to create the BitmapFont so I can use my own font instead of the default one. The text is rendered with no problems except it is fliped in the y axis, before using the TrueTypeFontFactory.createBitmapFont method I would just create a BitmapFont and pass true in the constructor in order to flip it, but now that I am using the TrueTypeFontFactory I can't do it that way, and I don't seem to be able to do it after the BitmapFont is created because there are no methods to do so. So I was wondering how could I flip the font in this case?

3

3 Answers

13
votes

You could try calling font.setScale(1, -1); after it is created, but I don't know of a better way.

2
votes

You can use FreeTypeFontParameter of flip=true function (parameter.flip=true) default is false

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font/font.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 12;
    parameter.flip=true;
    BitmapFont font = generator.generateFont(parameter); // font size 12 pixels 

Src : https://github.com/libgdx/libgdx/wiki/Gdx-freetype

1
votes

Set the boolean argument in the BitmapFont constructor to true:

//to load custom font:
font = new BitmapFont(Gdx.files.internal("data/fonts/font.fnt"), Gdx.files.internal("data/fonts/font.png"), true);
//to load default arial font:
font = new BitmapFont(true);