【问题标题】:Libgdx why is my button not responding on mouseclicksLibgdx为什么我的按钮在鼠标点击时没有响应
【发布时间】:2013-03-21 20:22:02
【问题描述】:

为什么我来自 libgdx 的 TextButton 对点击没有响应?

我有一个按钮,这个按钮有一个监听器,但它没有响应。 该按钮正在显示,但在单击鼠标时没有响应。

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);
}

【问题讨论】:

  • 有人知道为什么吗?

标签: java button libgdx mousepress


【解决方案1】:

为您的按钮添加一个 ClickListener。它看起来像这样。

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

另外,请确保将舞台设置为输入处理器,否则它将看不到事件。

Gdx.input.setInputProcessor(stage);

【讨论】:

  • 确保将Gdx.input.setInputProcessor(stage);添加到public void show(){}方法中
猜你喜欢
  • 1970-01-01
  • 2015-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-04
  • 1970-01-01
  • 2019-06-18
  • 1970-01-01
相关资源
最近更新 更多