1
\$\begingroup\$

I'm aiming for the following design in my app, and I am having a difficulty figuring how this could be achieved.

enter image description here

The purple part will be the main part of the game, which I have actually already written, implementing InputProcessor. It uses touch controls for dragging (mainly) and touching down or up with the finger.

I didn't think of creating a HUD beforehand and now decided that a Stage would work perfectly for that, but it definitely wouldn't work with the above input method. Is there a way to split the screen into areas like in the diagram, and depending on touch location pass the touch events to either main game InputProcessor or to the Stage?

\$\endgroup\$
5
  • \$\begingroup\$ I don't know it's good idea to just copy paste my own answer on SO to here. In short, you will combine technique of glViewport to draw onto target section on screen with proper management of camera i.e. OrthographicCamera and associated Viewport to achieve what you're trying to do. \$\endgroup\$
    – haxpor
    Commented Sep 6, 2017 at 6:21
  • \$\begingroup\$ Okay, I get the basic idea from the last paragraph. So if I split my view with rectangles, I can pass the touch on to my custom input. But what about the Stage? Can input be passed on to it? \$\endgroup\$
    – kacpr
    Commented Sep 6, 2017 at 10:53
  • \$\begingroup\$ Sorry, I didn't use Stage myself so I'm not in position to confidently answer. \$\endgroup\$
    – haxpor
    Commented Sep 6, 2017 at 11:38
  • 1
    \$\begingroup\$ You can use an inputMultiplexer to allow input to be passed to 2 input processors libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/… \$\endgroup\$
    – dfour
    Commented Sep 7, 2017 at 14:01
  • \$\begingroup\$ @dfour cheers, I've previously dismissed InputMultiplexer because for some reason when I attempted to use it, it caused a StackOverflowException, but after your comment I tried it again. Would you like to improve your answer into a full answer so I can accept it? \$\endgroup\$
    – kacpr
    Commented Sep 11, 2017 at 10:37

1 Answer 1

1
\$\begingroup\$

You can use an InputMultiplexer to combine 2 input processors. The multiplexer will accept stage as it is an inputProcessor which would be your GUI. You can then add your game's input processor as the second processor.

The second processor will only be triggered when the first input processor returns false indicating it has not handled the event and should be passed down the processor chain.

Stage myStage = new Stage(); // define your stage    

// create multiplexer
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(myStage); // set stage as first input processor
multiplexer.addProcessor(new MyGameInputProcessor());  // set your game input precessor as second
Gdx.input.setInputProcessor(multiplexer); // set multiplexer as input processor
\$\endgroup\$

You must log in to answer this question.

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