javaandroidperformancebitmap-fonts

LibGDX Bitmap Font Performance


I have a class extended to Actor

This is the draw function

@Override
public void draw(Batch batch, float parentAlpha) {
    batch.setColor(getColor());

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/myfont.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 30;
    parameter.borderColor = Color.BLACK;
    parameter.borderWidth = 2;
    BitmapFont font = generator.generateFont(parameter);
    font.draw(batch, "string", 220, 45);
}

It draws the font fine but the performance decreases noticeably. I couldn't figure it out. Any help will be appreciated.


Solution

  • It was because that I was creating the font in draw method. I put it to the show method and it works fine now.