Set fontsize for texts/labels?


with what attribute can I set the fontsize of a text element and/or label control? Or do I have to do it in my code?

I don’t think you can. You just have to make different font files and use them.

Normally people have a: small, medium, and large, font size, and use that based on resolution. Although I just use nifty autoscale now with a highish resolution


ekhm, with Text GUI element it’s possible…

[java]txt.setSize(fontConfig.myFont.getPreferredSize() * fontSize);[/java]

and Nifty dont let to set size?

then it’s good i have my own gui System…

Nifty (and the rest of JME3, and in fact most game engines) use bitmap fonts not truetype. This is because they are massively faster to render - and this stuff needs rendering every frame.

The bad thing though is that they are fixed size. You set the size of your text by selecting the font to use and its part of that selection. i.e. you might have Arial_18_bold, Arial_18_plain and Arial_20_bold as fonts. You then select the right font to get the effect and size you need.

You can, in fact, set the size of the font, however it may not look good.

Its basically scaling it up to match the size, so it will look the same as fonts as a zoomed in on a screenshot of text.

It would be nice to see Nifty develop a vector graphics rendering engine, or implement an existing one, so that it may render .ttf and .svg . The great processing loss can be averted by implementing a cache to bitmap interface for all vector graphics objects so that they can be cached to bitmap immediately after being transformed/animated.

1 Like

What works fi you work with jme labels directly:

Create a size 65 font or similar oversized, just use the scaleLocal to reduce the size to your needed one. Downsizing has less quality loss than upscaling :wink: