【问题标题】:How to scale BitmapFontShader from skin in libgdx?如何从 libgdx 中的皮肤缩放 BitmapFontShader?
【发布时间】:2014-08-11 07:42:28
【问题描述】:

这是我的皮肤文件:

{
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } },
com.badlogic.gdx.graphics.Color: {
    green: { a: 1, b: 0, g: 1, r: 0 },
    white: { a: 1, b: 1, g: 1, r: 1 },
    red: { a: 1, b: 0, g: 0, r: 1 },
    black: { a: 1, b: 0, g: 0, r: 0 }
},
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
    default: { down: Button-Pressed, up: Button },
    toggle: { down: Button-Pressed, checked: Button-Pressed, up: Button }
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
    default: { down: Button-Pressed, up: Button, font: default-font, fontColor: white },
    toggle: { down: Button-Pressed, up: Button, checked: Button-Pressed, font: default-font, fontColor: white, downFontColor: red }
},
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
    default: { titleFont: default-font, background: window, titleFontColor: white },
    dialog: { titleFont: default-font, background: window, titleFontColor: white }
},
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
    default: { font: default-font, fontColor: white }
},
}

我使用以下代码更改了默认字体:

texture = new Texture(Gdx.files.internal("default.png"), true);
bitmapFontShader = new BitmapFontShader(Gdx.files.internal("default.fnt"), new TextureRegion(texture), false, 1 / 5f);

skin = new Skin(Gdx.files.internal("myskin.json"));
skin.remove("default-font", BitmapFont.class);
skin.add("default-font", bitmapFontShader, BitmapFont.class);

现在我尝试缩放它:skin.getFont("default-font").scale(0.5f);,但它不起作用。 有人可以告诉我可能是什么原因?我的代码有什么问题?

【问题讨论】:

    标签: libgdx shader font-size


    【解决方案1】:

    请尝试从您的皮肤文件中删除以下行: com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } },

    然后使用以下代码加载:

    Skin skin=new Skin();
    skin.add("default-font", bitmapFontShader);
    skin.addRegions(new TextureAtlas(Gdx.files.internal("myskin.atlas")));
    skin.load(Gdx.files.internal("myskin.json"));
    

    【讨论】:

    • json文件中的默认字体怎么办?在窗口按钮等'...
    • 我相信 json 文件不需要更多的更改。只需缩放 skin.getFont("default-font").scale(0.5f);祝你好运。
    猜你喜欢
    • 2014-09-11
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 2015-12-24
    • 2014-06-22
    • 2017-04-27
    相关资源
    最近更新 更多