4

私のTextButton, from libgdx がクリックに応答しないのはなぜですか?

ボタンがあります。このボタンにはリスナーがありますが、応答しません。ボタンは表示されていますが、マウスをクリックしても反応しません。

public MyStage extends Stage {
     ...
     next.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
        {
            Gdx.app.log(ApothecaryGame.LOG, "Pressed: Next button.");
            return true;
        }
        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.app.log( ApothecaryGame.LOG, "Released: Next button.");
            super.touchUp( event, x, y, pointer, button );
            nextPage();
        }
    } );
    this.addActor(next);
}
4

1 に答える 1

15

ボタンに ClickListener を追加します。こんな感じになります。

button.addListener(new ClickListener() {
    public void clicked(InputEvent event, float x, float y) {
        // Do something interesting here...
    }
});

また、ステージが入力プロセッサになるように設定してください。そうしないと、イベントが表示されません。

Gdx.input.setInputProcessor(stage);
于 2013-03-31T21:54:39.360 に答える