Libgdx: setting a different screen, but still the buttons from the old screen are active

In my libgdx game , I have 2 screens, menu and list . When I click on the label on the menu screen, I do a setscreen(list) . A new screen will appear, and the menu screen with its shortcuts will disappear.

But when I click on the same positions (from the menu screen where the labels were, but, of course, these labels do not appear because I changed the screens), the click event responds. Why?

Note. On my list screen, there are currently no event handlers for any widget.

When switching screens, do I need to do more than just setscreen(anotherscreen) to turn off the old screen?

+6
source share
3 answers

I changed this:

I moved the input processor to the show () method of this screen using the stage variable of this screen

 public void show() { ... Gdx.input.setInputProcessor(stage); } 

before I set this only in the screen designer, so even if I changed the screen, the input processor was still bound to the last screen screen created

+13
source

The answer above adiddnt works for me because I am not working with InputProcessor on the second screen.

My solution was to set InputProcessor to null after setScreen.

Gdx.app.getApplicationListener().setScreen(new Screen()); Gdx.input.setInputProcessor(null);

+2
source

Just broke my head over this. I changed the screens in the show method, but after that I called Gdx.input.setInputProcessor(stage) . The method is still completed after the show method of the new screen was launched and, thus, returned to the previous step.

Therefore, before changing screens or return you call Gdx.input.setInputProcessor(stage) after changing screens.

0
source

Source: https://habr.com/ru/post/951481/


All Articles