libGDX MENU按钮
问题描述:
我有一款游戏,其中有一些功能按钮,其定义为ImageButtons
。我有一些其他的形状,这是Sprites
。在每种类型的元素上都有自己的侦听器类型。我通过MENU
按钮设置活动功能按钮“Stage
”。 这是不实际的,因为更新的设备没有MENU
按钮。libGDX MENU按钮
@Override
public boolean keyDown(int keycode) {
if ((keycode == Keys.M) || (keycode == Keys.MENU)) {
// some code
}
您怎么看待,我该如何更换这个“方法”?
答
我已经使用InputMultiplexer
解决了这个问题。这是非常容易使用,并伎俩。你应该这样实现:
public InputMultiplexer(InputProcessor... processors)
答
问题中没有足够的信息。 但不管怎么说有一个非标准按钮创建:
//set the buttonStyle/load texture/etc.
ImageButton playButton = new ImageButton(buttonStyle);
//create a stage
Stage stage = new Stage();
stage.addActor(playButton);
//
//now, set the input processor to this stage
Gdx.input.setInputProcessor(stage);
//and add the clicklistener to the button
playButton.addListener(new ClickListener(){/*override the down/up funcs*/});
这个U可以只是链接按钮到新阶段后,设置inputproccessor,这将在新设备上也行:
//create new stage
Stage stage1 = new Stage();
stage1.addActor(oldScreen.playButton);
Gdx.input.setInputProcessor(stage1);
希望这有助于。
+0
已经有两个不同的阶段与不同的按钮。 我他们之间改变的keyDown函数内部,就像这样: 'ExitButton.addListener(新ClickListener(){ @覆盖 公共无效点击(InputEvent的事件,浮法X,浮法Y){ Gdx.input.setInputProcessor(对话); pause(); } });' 默认为inputController。 – plaidshirt
你在这里想达到什么目的?由于ImageButton使用触摸/鼠标点击来激活,而不是来自InputProcessor的keyDown。 –
为什么不使用只在GUI上放置一个菜单按钮(例如在一个角落),如下所示:http://cdn.gottabemobile.com/wp-content/uploads/2011/12/ICS-Screen05。 jpg – gaRos
@ p.streef:已有2种不同类型的侦听器。我无法使用按钮在侦听器之间切换。 – plaidshirt