[英]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.