0
\$\begingroup\$

On my screen I want to display two controllers, one to turn around the character (We'll call itLook) and one to move the character (We'll call it Move).
I have a line registering a ControllerListener Which implements InputProccessor.
My question is if I can use the ControllerListener to receive input from both Move and Look at the same time.
In case that wasn't clear, I mean I want the player to maneuver the map using both controllers, not just one.

\$\endgroup\$
1
  • \$\begingroup\$ What do you mean by controllers? To me a controller is like a PS3/XBOX controller, is that what you mean? \$\endgroup\$
    – nathan
    Commented Feb 11, 2014 at 23:47

1 Answer 1

0
\$\begingroup\$

On Desktop, for example, in your keyDown() method, you should check for all the expected input events at the same time, not just one per method call. So, if you want both move and look to be triggered, you should do something like this:

@Override
public void keyDown(int keycode) {
    if (keycode == Keys.A) inputController.moveLeft();
    if (keycode == Keys.W) inputController.moveForward();
    if (keycode == Keys.D) inputController.moveRight();
    if (keycode == Keys.S) inputController.moveBackward();

    if (keycode == Keys.LEFT) inputController.lookLeft();
    if (keycode == Keys.UP) inputController.lookUp();
    if (keycode == Keys.RIGHT) inputController.lookRight();
    if (keycode == Keys.DOWN) inputController.lookDown();
}

If you check your input event with elses, the first triggered event will be processed, all the others will be ignored, I guess you can see the difference.

Of course, you can play with your code to split this into two different input controllers, or even two different input processors. If you choose to use two different input processors at a time, you will have to set them both using an InputMutiplexer when setting the input processing handler on the game screen, like this:

final InputMultiplexer inputMultiplexer = new InputMultiplexer();
inputMultiplexer.add(new MovementInputProcessor());
inputMultiplexer.add(new LookInputProcessor());
Gdx.input.setInputProcessor(inputMultiplexer);

This is to be implemented in a similar fashion for Android.

Hope this helps.

\$\endgroup\$
2
  • \$\begingroup\$ I am making the game only for android, can I use the InputMultiplexer the same way for android too and just create two separate Input Processors? \$\endgroup\$ Commented Feb 12, 2014 at 11:00
  • \$\begingroup\$ Yes, you can. You'd just have to handle input in an Android specific manner, by implementing the touchDown() and touchUp() methods, and since libgdx is cross platform, it means the same concepts work for Android too. Plus to this, you can combine touch input handling and accelerometer handling to achieve, for example, movement via accelerometer and look via touch. But that's just one option of course. \$\endgroup\$
    – VictorB
    Commented Feb 12, 2014 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .