3

在 libGdx(在 Android 中)中是否有类似 touchdown 事件的等价物 - 所以当用户触摸屏幕(并连续按住手指)时,即 touchhelddown 方法?

4

1 回答 1

8

您可以使用GestureDetector. 它实现InputAdapter了,因此您可以使用它代替您的 InputAdapter 或与您的 InputAdapter 一起使用InputMultiplexer.

你需要提供一个GestureListener给它。GestureDetector 在检测到支持的手势时调用 GestureListener 的方法。这些方法和手势是:

public boolean touchDown (int x, int y, int pointer);
public boolean tap (int x, int y, int count);
public boolean longPress (int x, int y);
public boolean fling (float velocityX, float velocityY);
public boolean pan (int x, int y, int deltaX, int deltaY);
public boolean zoom (float originalDistance, float currentDistance);
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, 
                      Vector2 firstPointer, Vector2 secondPointer);

您可以扩展GestureAdapter和覆盖您感兴趣的方法。在您的情况下,您将覆盖longPress方法。您还可以将longPressDuration其作为参数提供给构造函数。

于 2012-04-08T19:51:52.633 回答