1. How to get the stage to accept touch events:
Register Listener
Inputmultiplexer inputmultiplexer = new Inputmultiplexer (Getstage (), new Gesturedetector (this));
Gdx.input.setInputProcessor (Inputmultiplexer);
The second one here is for gesture monitoring. (Slide, zoom, etc.)
2. Here is a special note that all events are processed before they are drawn.
Gdx.input.justTouched ()
Gdx.input. Istouched ()
The above two methods are used to get the screen whether there is a click (Touchdown action).
It's not a good idea to switch between screens if you want to use the above method.
if (Gdx.input.justTouched ()) {
If The screen was touched, go to the next screen
}
When you switch to the second screen, the second screen accepts the Touchup event, and if some variables involve touchdown processing, an error occurs.
The reasons are as follows:
The first screen processing down event, switch Screen,screen registers the event receiver for drawing processing--now that the second screens are displayed, the up event is processed.
an event, starting in touchdown, and finally touchup!
PS: If you want to switch screen by clicking, you can do it by clicking on a control, such as image.
Image screenbg .... Background layer, consistent with screen size
Screenbg.addlistener (New Inputlistener () {
@Override
public boolean TouchDown (InputEvent event, float x, float y, int pointer, int button) {
The Touchup event is triggered only if true is returned.
return true;
}
@Override
public void TouchUp (InputEvent event, float x, float y, int pointer, int button) {
if (conditional trigger) {
Chgame.getinstance (). Setscreen (Nextscreen);
}
}
});
LIBGDX Touch Event resolution