i have trouble having scale font in libgdx. I want use 1 file .fnt to 3 different font scale. But the result the font still have same scale whatever i scale them 1 by 1 .
this is my code, i'm using AssetManager.
// this is I load the assetsFont
// Settings.fileSilverBoldFont is font location.
// load font
manager.load(Settings.fileSilverBoldFont, BitmapFont.class);
BitmapFont defaultFont = manager.get(Settings.fileSilverBoldFont, BitmapFont.class);
// edited, old -> defaultSmall = defaultFont; (reference object, my fault)
BitmapFont defaultSmall= new BitmapFont(defaultFont.getData(), defaultFont.getRegion(), true);
BitmapFont defaultNormal= defaultFont.getCache().getFont();
BitmapFont defaultBig= new BitmapFont(defaultFont.getData(), defaultFont.getRegion(), false);;
// set font sizes
defaultSmall.setScale(0.75f / Settings.widthRatio, 0.75f / Settings.heightRatio);
defaultNormal.setScale(1.0f / Settings.widthRatio, 1.0f / Settings.heightRatio);
defaultBig.setScale(2.0f / Settings.widthRatio, 2.0f / Settings.heightRatio);
// enable linear texture filtering for smooth fonts
defaultSmall.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultNormal.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultBig.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
Then i fill my font to my game controller initFont().
public void initFont(){
distanceFont = new BitmapFontCache(Assets.assetFont.defaultBig).getFont();
scoreFont = new BitmapFontCache(Assets.assetFont.defaultSmall).getFont();
}
At last i Render my font to screen in render(), I call game controller using variable controller.
public void render(float delta){
controller.scoreFont.draw(hudBatch, controller.scoreText, 160/Settings.widthRatio, hudCam.viewportHeight - (40/ Settings.heightRatio));
controller.distanceFont.draw(hudBatch, controller.distanceText, hudCam.viewportWidth/2, hudCam.viewportHeight - (40/ Settings.heightRatio));
}
I want to have scoreFont draw Small and distanceFont draw big font. but the result 2 of them still have same size. How can i have my scoreFont draw with small font and distanceFont draw with big font ?
found about reference object in java, now i'm change using new object of it, and it still same, I can't have different size of font.
Okey now i found, I must load using BitmapFont directly multiple times, this is solution what i do. I don't know how to use AssetManager properly to do that, maybe this is enough for this case.
// create three fonts using Libgdx's built-in 15px bitmap font
silverBoldSmall = new BitmapFont(Gdx.files.internal(Settings.fileSilverBoldFont));
silverBoldNormal = new BitmapFont(Gdx.files.internal(Settings.fileSilverBoldFont));
silverBoldBig = new BitmapFont(Gdx.files.internal(Settings.fileSilverBoldFont));
// set font sizes
silverBoldSmall.setScale(2f / Settings.widthRatio, 2f / Settings.heightRatio);
silverBoldNormal.setScale(3f / Settings.widthRatio, 3f / Settings.heightRatio);
silverBoldBig.setScale(4f / Settings.widthRatio, 4f / Settings.heightRatio);