计算机不知道这一点。或者至少界面不会告诉你这个信息。它看起来像这样:
public boolean touchDragged(int screenX, int screenY, int pointer);
它与 touchDown 几乎相同:
public boolean touchDown(int screenX, int screenY, int pointer, int button);
After a touchDown
事件发生了,仅touchDragged
事件将发生(对于同一指针)直到touchUp
事件被解雇。如果您想知道指针移动的方向,您必须通过计算最后一个触摸点与当前触摸点之间的增量(差异)来自行计算。这可能看起来像这样:
private Vector2 lastTouch = new Vector2();
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
lastTouch.set(screenX, screenY);
}
public boolean touchDragged(int screenX, int screenY, int pointer) {
Vector2 newTouch = new Vector2(screenX, screenY);
// delta will now hold the difference between the last and the current touch positions
// delta.x > 0 means the touch moved to the right, delta.x < 0 means a move to the left
Vector2 delta = newTouch.cpy().sub(lastTouch);
lastTouch = newTouch;
}