简体   繁体   English

LibGdx-我如何从播放器中获取输入,但又可以从舞台中获取输入

[英]LibGdx - How do I take input from my player, but also be able to take input from a stage

Basically I have a game, where the player on the map is handled by wasd using an InputProcessor. 基本上,我有一个游戏,其中地图上的玩家是使用InputProcessor由wasd处理的。 My problem is I cant have 2 input processors at the same time, and to me it seems as if I need 2. What is the suggested way of doing this? 我的问题是我不能同时拥有2个输入处理器,在我看来,我好像需要2个。建议的这样做方式是什么?

This is a very common case and that's why libGDX has an InputMultiplexer to forward the events to both InputProcessors . 这是一个非常常见的情况,这就是libGDX具有InputMultiplexer来将事件转发到两个InputProcessors

You basically use it like this: 您基本上是这样使用它的:

InputProcessor inputProcessorOne = new CustomInputProcessor();
InputProcessor inputProcessorTwo = stage;
InputMultiplexer inputMultiplexer = new InputMultiplexer();
inputMultiplexer.addProcessor(inputProcessorOne);
inputMultiplexer.addProcessor(inputProcessorTwo);
Gdx.input.setInputProcessor(inputMultiplexer);

See libgdx multiple objects implementing InputProcessor for a bit more detailed explanation. 有关更多详细说明,请参见libgdx实现InputProcessor的多个对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从一个班级的扫描仪中获取输入并将其放入另一班级 - How do I take an input from my scanner from one class and put it in another class 如何将函数作为Java中JTextField的输入? - How do I take a function as an input from a JTextField in Java? 我如何修正我的while语句,以便仅从输入中获取数字? - How do I fix my while statement in order to only take numbers from an input? 如何获取用户输入并将其显示在阵列上? - How do I take user input and show it on my array? 在 java 中,如何从 Jbutton 获取值,因为它是来自键盘的输入? - In java How Do I Take A Value From a Jbutton As It Is An Input From The Keyboard? 如何使Java程序从上一个循环中获取结果并将其输入到同一过程中? - How do I make a java program take the results from a previous loop and input it in the same process? 如何从一个 class 中的扫描仪获取用户输入,然后将其应用于同一 package 中的另一个 class? - How do I take an user input from Scanner in one class and then apply it to another class in the same package? 如何从Java中的控制台获取String输入? - How to take String input from console in Java? 如何参与输入号码? - How to take part from input numbers? Java:如何从USB视频捕获设备获取输入? - Java: How do I take input from a USB video capture device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM