Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx how to flip a BitmapFont?

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?

like image 542
Leonso Medina Lopez Avatar asked Nov 01 '12 23:11

Leonso Medina Lopez


2 Answers

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

like image 132
Zoodinger Avatar answered Sep 23 '22 12:09

Zoodinger


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

like image 29
Ferhat KOÇER Avatar answered Sep 22 '22 12:09

Ferhat KOÇER