2
votes

Helo guys! I'm trying to set size of the text in TextButton using libgdx and scene2d.

Here's how I create and initialize textbutton object:

Skin skin = new Skin();
skin.add("white", new Texture(Gdx.files.internal("data/texture.jpg")));
skin.add("default", new BitmapFont());

TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white");
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);

TextButton newGame = new TextButton("Hello button",skin);

After that the button with text in it is created perfectly, but I don't understand how can I change it's text size.

I've already tried almost every method of Label object:

newGame.getLabel().setScale(10);
newGame.getLabel().setWidth(100);

And so on. So my question is: How can I change text size in TextButton?

2

2 Answers

3
votes

Try setting the font scale to Button's label.

tb.getLabel().setFontScale(5.0f);

2
votes

Try just changing the size of the font by scaling. textButtonStyle.font.setScale(..)

Id recommend to take a look at the FreeTypeFontGenerator with it help you can create fonts in different sizes without scaling, out of regular .tff files.