LibGdx:使用手势侦听器 [英] LibGdx: Utilizing a Gesture Listener

查看:103
本文介绍了LibGdx:使用手势侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用一些您无法访问的更复杂的触摸屏手势

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

Gdx.input

我看到要执行此操作,我必须创建一个Gesture侦听器,因此我创建了GestureHandler类,并从维基.我的手势处理程序如下:

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!

推荐答案

来自 Wiki :

A GestureDetector是变相的InputProcessor.听 手势,必须实现GestureListener接口, 将其传递给GestureDetector的构造函数.探测器是 然后在InputMultiplexer上设置为InputProcessor或 主要的InputProcessor

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

我承认那是相当密集的.但是在Wiki上您会看到更远的地方:

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

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

用希望不太密集的英语来重述上述内容:您的 GestureHandler实例被传递给 Libgdx GestureDetector实例.该对象将积累原始"输入并将其转换为更高级别的手势".要获取原始输入,需要将原始输入安装到原始输入.通过Gdx.input.setInputProcessor进行安装的最基本方法,但是您也可以通过InputMultiplexer进行安装(但这不值得在这里介绍).

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).

这篇关于LibGdx:使用手势侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆