LIBGDX Touch Event resolution

Source: Internet
Author: User
Tags libgdx

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.