Changing font size in skin

好久不见. 提交于 2019-12-07 16:56:00

问题


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)


回答1:


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);



回答2:


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)




回答3:


As of 2017 i had to use

skin.getFont("default-font").getData().setScale(0.5f);

for future users.



来源:https://stackoverflow.com/questions/20301964/changing-font-size-in-skin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!