gpt4 book ai didi

java - libgdx 中的 GestureDetector 和 InputListener

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:10 24 4
gpt4 key购买 nike

我是 libgdx 的新手,我在这里想要实现的是我希望我的 GestureDetector 与 InputListener 同时工作。我的左边有两个按钮,即使我同时开始滑动(多点触控),我也需要它们保持 react 。我使用了 InputMultiplexer 但它无法按我需要的方式工作。我检查了 InputListener 和 GestureDetector 的所有返回值,我需要的一切都返回 true,GestureInputListener 也是一个实现 GestureDetector.GestureListener 的类。我只在其中使用了fling。 GestureInputListener 和 InputListener 都可以工作,但不能同时工作。你能帮我吗?链接,想法。谢谢。代码如下:

inputMultiplexer.addProcessor(stage);
inputMultiplexer.addProcessor(new GestureDetector(gestureInputListener));
Gdx.input.setInputProcessor(inputMultiplexer);

最佳答案

在使用以下任何类(GestureDetector 或 InputProcessor)时,如果您从其函数返回 true,则它不会检查连接到您的游戏的任何其他处理器。

在您的代码中,您首先添加了阶段,然后添加了手势检测器,如果您的阶段正在工作并处理输入并返回 true,那么您的手势检测器将不会调用各种功能。

如果你想让你的舞台和手势检测器都工作,那么永远不要从你的手势监听器和舞台中的任何函数返回真值


InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(new MyUiInputProcessor());
multiplexer.addProcessor(new MyGameInputProcessor());
Gdx.input.setInputProcessor(multiplexer);

The InputMultiplexer will hand any new events to the first InputProcessor that was added to it. If that processor returns false from the method invoked to handle the event, this indicates the event was not handled and the multiplexer will hand the event to the next processor in the chain. Through this mechanism, the MyUiInputProcessor can handle any events that fall inside one of its widgets and pass on any other events to the MyGameInputProcessor.

Libgdx Wiki InputEvent

关于java - libgdx 中的 GestureDetector 和 InputListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18559583/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com