我一直在尝试向我的游戏中添加一个按钮,即使我查找了所有的解决方案,似乎什么都不起作用。
按钮可以正常渲染,但是当我点击它时却没有任何反应。
我一直在使用一个 InputMultiplexer
在舞台上设置输入处理器,并将按钮添加为演员。
任何帮助将不胜感激。
this.stage = new Stage();
...
this.buttonReplay = new TextButton("Replay", buttonStyle);
this.buttonReplay.setX(width / 2 - this.buttonReplay.getPrefWidth() / 2);
this.buttonReplay.setY(height / 2 - this.buttonReplay.getPrefHeight() / 2);
this.stage.addActor(buttonReplay);
(不同的类)
multiplexer.addProcessor(menuDeath.getStage()); // Adds death menu to input processor
Gdx.app.log("adddad", "added");
menuDeath.getButtonReplay().addListener(new InputListener()
{
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button)
{
Gdx.app.log("dsad", "daDSAda");
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button)
{
Gdx.app.log("dsad", "daDSAda");
}
});
当运行时,“added”会在控制台中记录,这应该意味着
stage
有一个输入处理器,然而,按钮似乎根本不起作用,我甚至尝试使用不同的监听器,如ClickListener
和ChangeListener
。