Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing font size in skin

I am writing a game using libgdx, and I borrowed the skin.json (and related files) from a tutorial.

The font being used (default) was scaling in an ugly manner on denser screens, so I generated by own very large font - and in the game itself, I scale it to a reasonable size (basically I use BitmapFont.scale). The font I'm now using is 3 times as large as the previous one.

I changed the reference to which font to use in the skin.json file, and as a result, all my buttons, titles and other things have a massive font being shown.

Is there a way of scaling the font in the .json file? Or anywhere else in the code? Skin doesn't have a setFont() functionality, so I can't create a scaled BitmapFont and assign it)

like image 523
Haedrian Avatar asked Nov 30 '13 15:11

Haedrian


People also ask

How do I change the font size on Windows 10?

Change system font size in Windows 10 In Settings, you can click Ease of Access. Click Display in the left panel. In the right window, you will see a Make text bigger option.

How do I change the font size on Steam?

11) Open Steam and select Settings. 12) In Settings select Interface. 13) In Interface change the skin to 'IncFont' and click 'OK'. 14) Steam will restart with the new font size increases. If a font increase of 2 points is not enough for you, repeat step 9 adding a further 2 points. Keep repeating step 9 until you are happy with the results.

How to make a font bigger on screen?

What to Know 1 The easiest way to make a font bigger onscreen is to use the keyboard shortcut for zoom; use the Ctrl or Cmd key and tap... 2 You can also use Windows or Mac Zoom settings from the Personalize or Preferences menu. 3 You may be able to make a font bigger using the settings in your favorite web browser, as well. More ...

How to change font size on MacBook Air?

How to Change the Font Size on My Mac Something else you can try if the other methods aren't working to increase the font size on your Mac is to adjust your computer's screen resolution: 1 From the main Apple menu, select System Preferences . 2 Choose Displays and then Display . 3 Select Scaled and then choose a lower resolution. See More....


2 Answers

Libgdx changed this back in April 2015 so that the set answer doesn't work anymore. Took a little bit to find the answer, so I thought I'd leave it here for others since this answer pops up first in Google.

this.getSkin().getFont("default-font").getData().setScale(0.33f,0.33f);
like image 58
Frackinfrell Avatar answered Sep 29 '22 07:09

Frackinfrell


Documentation says that any gets will return a handle to the actual object. So changes will persist.

So I changed the font in skin.json to point to my new font.

Then I used this code

this.getSkin().getFont("default-font").setScale(0.33f, 0.33f);

To scale the 'default-font' (as defined in the skin.json) to the scale I wanted (in my case its 0.33f)

like image 42
Haedrian Avatar answered Sep 29 '22 09:09

Haedrian