【问题标题】:TextButton does not receive clicks in LibGDXTextButton 在 LibGDX 中不接收点击
【发布时间】:2016-06-06 10:52:52
【问题描述】:

这是我的代码:

public WelcomeScreen(final WallGame game) {
    this.game = game;
    // Setting up camera and viewport.
    camera = new OrthographicCamera();
    viewport = new StretchViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera);
    viewport.apply();
    stage = new Stage(viewport);
    camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
    Gdx.input.setInputProcessor(stage);

    skin = new Skin(Gdx.files.internal("uiskin.json"));
    skin.getFont("default-font").getData().setScale(0.1f, 0.1f);

    backgroundTxtr = new Texture(Gdx.files.internal("background/background.png"));
    background = new Image(backgroundTxtr);
    background.setBounds(0, 0, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);

    final TextButton button = new TextButton("start", skin, "red-button");
    button.setBounds(10, 10, 50, 50);
    button.setTouchable(Touchable.enabled);
    button.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            Gdx.app.log("AKS", "CLICKED");
        }
    });

    final Dialog dialog = new Dialog("Click Message", skin);
    dialog.setBounds(50, 50, 40, 40);

    stage.addActor(background);
    stage.addActor(button);
    stage.addActor(dialog);

}

我似乎无法使按钮工作,单击按钮时我有一个图像要显示(TextButton 的“向下”属性),但它没有改变。我做错了什么?

【问题讨论】:

    标签: libgdx


    【解决方案1】:

    我想通了。我还没有创建一个 Table 对象来添加按钮。在我这样做之后它就起作用了。

    【讨论】:

    • 表格不应该是按钮起作用的必要条件。
    • 你当然不需要一张桌子来有一个按钮。肯定有其他问题。
    • 是的,你是对的,我刚刚删除了桌子,它仍然有效。我不确定当时的问题是什么。
    猜你喜欢
    • 2015-02-26
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多