LibGDX True Type 字体在按钮中的使用
LibGDX True Type Font usage in button
所以我正在尝试使用真正的类型按钮,我设法用标签做到了并且效果很好,但现在我不知道如何将它与按钮一起使用。
我正在使用 GDX 自由字体库。
我在标签中使用:
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("LoginScreen/Fonts/bebas.ttf"));
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = (int) (0.05f * (stage.getHeight()));
BitmapFont font12 = generator.generateFont(parameter); // font size 12 pixels
generator.dispose(); // don't forget to dispose to avoid memory leaks!
LabelStyle labelStyle = new LabelStyle(font12, new Color(0, 0, 0, 0.5f));
windowTitle = new Label("Login or register", labelStyle);
我需要按钮:
loginButton = new TextButton("Sign in", skin, "default");
loginButton.getLabel().setFontScale(0.00444f * table.getWidth());
有一个 class 可以为您的按钮添加样式:
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.font = font12;
loginButton = new TextButton("Sign in", textButtonStyle);
但是你还必须配置其他东西。
所以我正在尝试使用真正的类型按钮,我设法用标签做到了并且效果很好,但现在我不知道如何将它与按钮一起使用。 我正在使用 GDX 自由字体库。
我在标签中使用:
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("LoginScreen/Fonts/bebas.ttf"));
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = (int) (0.05f * (stage.getHeight()));
BitmapFont font12 = generator.generateFont(parameter); // font size 12 pixels
generator.dispose(); // don't forget to dispose to avoid memory leaks!
LabelStyle labelStyle = new LabelStyle(font12, new Color(0, 0, 0, 0.5f));
windowTitle = new Label("Login or register", labelStyle);
我需要按钮:
loginButton = new TextButton("Sign in", skin, "default");
loginButton.getLabel().setFontScale(0.00444f * table.getWidth());
有一个 class 可以为您的按钮添加样式:
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.font = font12;
loginButton = new TextButton("Sign in", textButtonStyle);
但是你还必须配置其他东西。