[SOLVED] How to Change Nifty Text Element size in Java depending on Resolution

Hello,

i have the following Nifty XML Element

<text id=“text_SCORE_lblP1” font=“Interface/font/menu.fnt” color="#ff6100ff" text=“SCORE” align=“left” valign=“top” />

The question is: How can i ‘scale’ the text element depending on the screen resolution ?
I tried to use the attribute textLineHeight=“XX” in the text element but it was never took into account.
I tried to scale the font itself but i failed.

is it possible without changing the font file resources temselves ?
Is there a way fron the bind method of the NiftyClassController to retrieve the JMENode of the text element to scale it ?

So far i tried;

 Element e = screen.findElementByName("text_SCORE_valP1");
if( e !=null)
    TextRenderer scoreP1=e.getRenderer(TextRenderer.class);

but i can’t find anything usefull from the TextRenderer class to retrieve a JME Node. is it even possible ?

Thanks for your precious help

Hello, finally i solved this by using multiple size of the same font conveted into .fnt.png files and i load instead of another based on the screen width with the following pattern :

<text id=“text_SCORE_lblP1” font="${CALL.getFontName()}" color="#ff6100ff" text=“SCORE” align=“left” valign=“top”/>

and

       public String getFontName()
       {
           int screenWidth = settings.getWidth();
           String fontname = "";
           if (screenWidth <= 1024)
               fontname = "Interface/Fonts/SnapITC-38.fnt";
           else if (screenWidth <= 1280)
                fontname = "Interface/Fonts/SnapITC-50.fnt";
           else if (screenWidth <= 2000)
                fontname = "Interface/Fonts/SnapITC-64.fnt";
           else
                fontname = "Interface/Fonts/SnapITC-96.fnt";
           return fontname;     
       }

it’s not ideal but i did not find a better idea. if someone as one feel free to share

thanks anyway

1 Like