我对LibGDX Skin类有一个问题

时间:2013-06-23 17:56:25

标签: java libgdx skin

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: No com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle registered with name: default
at com.badlogic.gdx.scenes.scene2d.ui.Skin.get(Skin.java:138)
at com.badlogic.gdx.scenes.scene2d.ui.Skin.get(Skin.java:125)
at com.badlogic.gdx.scenes.scene2d.ui.TextField.<init>(TextField.java:114)
at com.mathieu.develop.DevelopController.createButtons(DevelopController.java:56)
at com.mathieu.develop.DevelopController.<init>(DevelopController.java:49)
at com.mathieu.view.GameScreen.show(GameScreen.java:55)
at com.badlogic.gdx.Game.setScreen(Game.java:62)
at com.mathieu.game.MainGame.create(MainGame.java:19)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:132)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:112)

我尝试这样做时出现此错误:

Skin skin = new Skin(GS.textFieldAtlas);
objectTextFieldSetName = new TextField("Object", skin);

我正在尝试使用两个文件文件创建皮肤:

https://www.dropbox.com/s/85rlj4kjq95y3lv/textures.png https://www.dropbox.com/s/0az61wy2fbsmz8p/textures.pack

private TextureAtlas loadTexturePack() {
    try {
        return new TextureAtlas(Gdx.files.internal("images/textures.pack"));
    } catch(Exception ex) {
        System.out.println(ex);
    }
    return null;
}

我正在尝试创建一个文本字段,以便我可以输入。任何帮助都将不胜感激!

1 个答案:

答案 0 :(得分:2)

我认为你还需要描述每个对象是如何被皮肤渲染的。您可以使用JSON文件或以编程方式执行此操作。请参阅wiki中的此页面:http://code.google.com/p/libgdx/wiki/Skin#Skin_JSON

从上面页面上的JSON示例:

{
    com.badlogic.gdx.graphics.Color: {
        white: { r: 1, g: 1, b: 1, a: 1 },
        red: { r: 1, g: 0, b: 0, a: 1 },
        yellow: { r: 0.5, g: 0.5, b: 0, a: 1 },
    },
    com.badlogic.gdx.graphics.g2d.BitmapFont: {
        medium: { file: medium.fnt }
    },
    com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
        default: {
            down: round-down, up: round,
            font: medium, fontColor: white
            },
        toggle: {
            down: round-down, up: round, checked: round-down,
            font: medium, fontColor: white, checkedFontColor: red
        },
        green: {
            down: round-down, up: round,
            font: medium, fontColor: { r: 0, g: 1, b: 0, a: 1 }
        }
    }
}

皮肤正在寻找类似的东西。特别是'default'变量中定义的值。我认为它看起来像这样:

{
    com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
        default: {
            <fields defined in TextFieldStyle>
        }
    }
}

希望这是一些帮助!

路易斯