我一直在使用不同的Gesture Detector方法检测不同类型的输入。但是我想通过改变以下方法的参数来改变G.D的一些偏好:
public GestureDetector(float halfTapSquareSize,
float tapCountInterval,
float longPressDuration,
float maxFlingDelay,
GestureDetector.GestureListener listener)
我得到了http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/input/GestureDetector.html的代码
我对改变" halfTapSquareSize"
的价值特别感兴趣我如何在下面的代码中实现它?
public class MyGdxGame extends ApplicationAdapter implements GestureDetector.GestureListener {
@Override
public void create() {
super.create();
//Doing stuff at create
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
@Override
public void render() {
super.render();
//Rendering stuff
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
//disposing stufff
}
@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) {
// Doing stuff at tap
return true;
}
@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) {
//Doing stuff when paning
}
@Override
public boolean panStop(float x, float y, int pointer, int button) {
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;
}
}
答案 0 :(得分:1)
您的代码仅实现了GestureListener。这个监听器需要与GestureDetector相关联,然后需要注册GestureDetector来处理输入。
所以在你的MyGdxGame课程中,你需要这样的东西: -
GestureDetector input = new GestureDetector(this); // 'this' refers to your MyGdxGame instance
Gdx.input.setInputProcessor(input);
现在您可以为GestureDetector的构造函数提供额外的参数,正如您在帖子中提到的那样,或者使用GestureDetector的相关方法,如下所示:
input.setTapSquareSize(someFloatValue);