I have a class called AbstractGameScreen with the following signature:
public abstract class AbstractGameScreen extends InputAdapter implements Screen { ... }
All my screens extend this abstract class. Now the problem i am encountering is that in screens that use stages i already set the stage to be the inputprocessor. But if i do so, the keyUp method doesn't execute on back-key being pressed anymore. if i set the screen to be inputprocessor instead, the stage doesn't work. how do i work around this problem?
public class MenuScreen extends AbstractGameScreen {
@Override
public void show() {
stage = new Stage(new StretchViewport(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT));
Gdx.input.setInputProcessor(stage);
Gdx.input.setCatchBackKey(true);
instructionsVisible= false;
rebuildStage();
}
@Override
public boolean keyUp (int keycode) {
// Back to Menu
if (keycode == Input.Keys.ESCAPE || (keycode == Input.Keys.BACK && instructionsVisible)) {
instructionsVisible=false;
layerInstruction.setVisible(false);
layerControls.setVisible(true);
}
else
{
Gdx.app.exit();
}
return false;
}
In this case you need two InputProcessors- the
Stage
and yourAbstractScreen
. The way you do this is create a newInputMultiplexer
object and configure it something like this: