LIBGDX TextButton

时间:2018-01-17 13:26:57

标签: java libgdx

我尝试使用默认外观在界面上添加按钮失败。 (http://download.bitowl.de/defaultskin.zip

我的代码:

public class Core extends ApplicationAdapter {
    Stage stage;
    SpriteBatch batch;
    Texture background;
    TextButton button;
    Skin skin;

    OrthographicCamera camera;
    Vector3 mouse;

    @Override
    public void create() {
        camera = new OrthographicCamera();
        batch = new SpriteBatch();
        stage = new Stage();
        mouse = new Vector3();

        batch.setProjectionMatrix(camera.combined);
        background = new Texture("fondLogoTikal.jpg");

        skin = new Skin(Gdx.files.internal("ui/defaultskin.json"));
        TextButton button = new TextButton("Mon boutton", skin);
        button.setPosition(125, 200);
        stage.addActor(button);
    }

    public void resize(int width, int height) {
        camera.setToOrtho(false, width, height);
    }

    @Override
    public void render() {
        batch.begin();
        batch.setProjectionMatrix(camera.combined);
        batch.draw(background, 0, 0);
        batch.end();
    }

    @Override
    public void dispose() {
        batch.dispose();
        stage.dispose();
        background.dispose();
    }
}

我的错误:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: ui/defaultskin.json
at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:98)
at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:75)
at com.mygdx.game.Core.create(Core.java:32)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)

但是,我正确地将ui文件放在资源文件中。 如果我删除TextButton,我的代码可以正常工作

0 个答案:

没有答案