在 libGDX 中构建 GestureDetector
Constructing a GestureDetector in libGDX
我一直在使用不同的手势检测方法检测不同类型的输入。但是,我确实想通过更改以下方法的参数来更改 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;
}
}
您的代码仅实现了 GestureListener。此侦听器需要与 GestureDetector 相关联,然后需要注册 GestureDetector 来处理输入。
所以在您的 MyGdxGame class 中,您需要这样的东西:-
GestureDetector input = new GestureDetector(this); // 'this' refers to your MyGdxGame instance
Gdx.input.setInputProcessor(input);
现在您可以向 GestureDetector 的构造函数提供额外的参数,如您在 post 中所述,或者使用 GestureDetector 的相关方法,如下所示:
input.setTapSquareSize(someFloatValue);
我一直在使用不同的手势检测方法检测不同类型的输入。但是,我确实想通过更改以下方法的参数来更改 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;
}
}
您的代码仅实现了 GestureListener。此侦听器需要与 GestureDetector 相关联,然后需要注册 GestureDetector 来处理输入。
所以在您的 MyGdxGame class 中,您需要这样的东西:-
GestureDetector input = new GestureDetector(this); // 'this' refers to your MyGdxGame instance
Gdx.input.setInputProcessor(input);
现在您可以向 GestureDetector 的构造函数提供额外的参数,如您在 post 中所述,或者使用 GestureDetector 的相关方法,如下所示:
input.setTapSquareSize(someFloatValue);