我一直在尝试在游戏中添加一个按钮,即使在我查找了所有解决方案之后,似乎也无济于事。该按钮可以正常显示,但是当我触摸它时它什么也没做。
我一直在使用anInputMultiplexer
在舞台上设置输入处理器,并在其上添加了按钮作为actor。
任何帮助表示赞赏。
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");
}
});
运行时,控制台中会记录“添加”,这意味着该stage
处理器具有输入处理器,但是,该按钮似乎根本不起作用,我什至尝试使用像ClickListener
和这样的不同侦听器ChangeListener
多路复用器可以先将输入事件发送到另一个侦听器,该侦听器通过返回true来消耗输入事件。
您可以先尝试摆脱多路复用器,只是通过替换来确保代码工作正常
multiplexer.addProcessor(menuDeath.getStage());
和
Gdx.input.setInputProcessor(menuDeath.getStage());
这样,menuDeath阶段是唯一的侦听器,因此应正确处理touchDown事件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句