LibGdx: Utilizing a Gesture Listener

China☆狼群 提交于 2019-12-14 03:55:51

问题


I would like to use some of the more complex touch screen gestures that you can't access from

Gdx.input

I saw that to do this i must create a Gesture listener so i created the class GestureHandler and copied the code from the wiki. My gesture handler looks like this:

public class GestureHandler implements GestureListener {

@Override
public boolean touchDown(float x, float y, int pointer, int button) {
    return false;
}

@Override
public boolean tap(float x, float y, int count, int button) {
    return false;
}

@Override
public boolean longPress(float x, float y) {
    return false;
}

@Override
public boolean fling(float velocityX, float velocityY, int button) {
    return false;
}

@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
    return false;
}

@Override
public boolean zoom(float initialDistance, float distance) {
    return false;
}

@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
    return false;
    }   
 }

My question is now that i have set up the gesture listener how can i use it. How can i get the info from these methods? Thank you for any help!


回答1:


From the wiki:

A GestureDetector is an InputProcessor in disguise. To listen for gestures, one has to implement the GestureListener interface and pass it to the constructor of the GestureDetector. The detector is then set as an InputProcessor, either on an InputMultiplexer or as the main InputProcessor

I admit that is rather dense. But a bit farther down on the wiki you'll see:

Gdx.input.setInputProcessor(new GestureDetector(new MyGestureListener()));

To rephrase the above in hopefully less dense English: Your GestureHandler instance is passed to a Libgdx GestureDetector instance. That object will accumulate "raw" inputs and convert them into higher-level "gestures". To get the raw inputs, it needs to be installed where the raw inputs will be delivered to it. The most basic way to install it via Gdx.input.setInputProcessor, but you could also install it via an InputMultiplexer (but that's not worth getting into here).



来源:https://stackoverflow.com/questions/17891366/libgdx-utilizing-a-gesture-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!