gpt4 book ai didi

java - 无法使用 Skin 更改 TextButton 的字体

转载 作者:行者123 更新时间:2023-12-02 02:37:20 28 4
gpt4 key购买 nike

我使用 uiskin.png、uiskin.atlas、uiskin.json 和 default.fnt 作为此链接提供的后续代码的资源。 https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests-android/assets/data

首先,我从 ttf 文件创建一个 BitmapFont,因为它支持任何大小而不会像素化。然后,我将 uiskin.json 加载到我的 skin 中。之后,我删除默认字体并将生成的 tff 字体添加到 skin 中,如下所示 默认字体

虽然我更改了default-font,但字体并未更改。问题出在哪里呢?如何更改皮肤的字体?

注意:我已经测试过显示 mainMenuFont50。该字体似乎工作正常。

public class Screen{
private BitmapFont mainMenuFont50;
private Stage stage;
private Skin skin;
private TextButton buttons;

public Screen(GdxGame game){
//creating BitmapFont from ttf
generator = new FreeTypeFontGenerator(Gdx.files.internal("font/Capture_it.ttf"));
parameter = new FreeTypeFontParameter();
parameter.size = 50;
mainMenuFont50 = generator.generateFont(parameter);
generator.dispose();

this.skin = new Skin();
this.skin.load(Gdx.files.internal("ui/uiskin.json"));
this.skin.remove("default-font", BitmapFont.class);
this.skin.add("default-font", mainMenuFont50);

buttons = new TextButton("Hello World", skin);
stage.addActor(buttons);
}
}

最佳答案

您无法更改皮肤的字体。构建皮肤并添加您的自定义字体。

请按照以下步骤操作:

  • 使用默认构造函数创建空白皮肤。

    Skin skin = new Skin();
  • 将所需字体添加到生成的皮肤

    skin.add("font", mainMenuFont50);
  • 将您的图集文件添加到您的皮肤中。

    skin.addRegion(new TextureAtlas(Gdx.files.internal("uiskin.atlas")));
  • 编辑 json 文件并将其加载到您的皮肤。

    skin.load(Gdx.files.internal("uiskin.json"));
  • 您的 JSON 文件包含“字体”引用

    {
    font: font
    }

关于java - 无法使用 Skin 更改 TextButton 的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46086788/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com