问题
In my libgdx game
, I have 2 screens, menu
and list
.
When I click on a label
in the menu
screen, I do a setscreen(list)
.
The new screen shows up, and the menu screen alongwith its labels disappears.
But when I click on the same positions (from menu screen where the labels were, but of course those labels are not showing as I have changed screens) the click event responds. Why?
note:My list screen currently has not event handlers for any widget.
When switching screens do I need to do anything more than just setscreen(anotherscreen)
to deactivate oldscreen?
回答1:
I changed this :
I moved the input processor to the show() method of that screen using stage variable of that screen
public void show() {
...
Gdx.input.setInputProcessor(stage);
}
before I was setting this only in the constructor of the screen, so even If I was changing the screen, the input processor was still attached to the last created screen's stage
回答2:
The answer above adiddnt work for me because I dont work with a InputProcessor in the 2nd screen.
My Solution was to set the Inputprocessor to null after setScreen.
Gdx.app.getApplicationListener().setScreen(new Screen());
Gdx.input.setInputProcessor(null);
回答3:
Just broke my head over this. I changed screens in the show
method but had Gdx.input.setInputProcessor(stage)
called after that. The method still completed after the show
method of the new screen ran and thus reverting back to the previous stage.
So make sure you call Gdx.input.setInputProcessor(stage)
before you change screens or return
after you change screens.
来源:https://stackoverflow.com/questions/18170274/libgdx-setting-another-screen-but-still-buttons-from-old-screen-active