如何分离Stage侦听器和InputProcessor侦听器 - libGDX

时间:2015-12-03 19:54:02

标签: java libgdx

我有两个演员:

enter image description here

和:

enter image description here

我首先将蓝色演员添加到舞台上,其次是红色演员:

blueActor.setPosition(100, 100, Align.center);
redActor.setPosition(100 - 20, 100 + 20, Align.center);

blueActor.addListener(blueListener);
redActor.addListener(redListener);

stage.addActor(blueActor);
stage.addActor(redActor);

这些演员看起来像这样:

enter image description here

如果他们的InputListenerZIndex,他们的听众Touchable依赖于enable,如下所示:

enter image description here

到目前为止,如果屏幕的输入处理器阶段,一切正常:

Gdx.input.setInputProcessors(stage);

如果屏幕的输入处理器是两个处理器StageInputProcessor

inputMultiplexer = new InputMultiplexer(this, stage);
Gdx.input.setInputProcessor(inputMultiplexer);

如图所示,将触及两个演员:

enter image description here

在这种情况下 HOW 我可以像第一种情况一样分开这些演员的两个听众吗?

1 个答案:

答案 0 :(得分:2)

Multiplexer后,public InputMultiplexer (InputProcessor... processors) { for (int i = 0; i < processors.length; i++) this.processors.add(processors[i]); } 的构造函数按您添加的顺序添加参数。

touchDown

然后在public boolean touchDown (int screenX, int screenY, int pointer, int button) { for (int i = 0, n = processors.size; i < n; i++) if (processors.get(i).touchDown(screenX, screenY, pointer, button)) return true; return false; } 事件中,它以相同的顺序运行它们。

inputMultiplexer = new InputMultiplexer(this, stage);

请注意,一旦any返回true,它也会返回true并停止循环。

所以当你这样做时:

touchDown

首先为this执行stage,然后为inputMultiplexer = new InputMultiplexer(stage, this); 执行Multiplexer。由于Red在舞台上,你会想要切换这样的顺序,以便Red可以先处理事件。

0 [sig] bash 9796 get_proc_lock: Couldn't acquire sync_proc_subproc for(5,1), last 7, Win32 error 0

但是,让我们说你现在有绿色,这也是在舞台上,但应该落后于蓝色。您必须创建自己的1040 [sig] bash 9796 proc_subproc: couldn't get proc lock. what 5, val 1类,可能是子类,只需覆盖touchDown,并使用您自己的方法组合/排序每个处理器中的对象侦听器,该方法使用zIndex来决定顺序 < / p>

相关问题