如何从 onDragUpdate 获取方向

How to get direction from onDragUpdate

你如何从 onDragUpdate 获得方向?

  Vector2 dragDeltaPosition = Vector2(0, 0);
  Vector2 dragDirectionVector = Vector2(0, 0);

  @override
  bool onDragStart(DragStartInfo info) {
    dragDeltaPosition = info.eventPosition.game - position;
    return false;
  }

  @override
  bool onDragUpdate(DragUpdateInfo info) {
    // double x = info.eventPosition.game.x - dragDeltaPosition.x;
    // double y = info.eventPosition.game.y - dragDeltaPosition.y;

    // double x = info.eventPosition.game.x - info.delta.game.x;
    // double y = info.eventPosition.game.y - info.delta.game.y;

    dragDirectionVector = Vector2(x, y);
  }

更新:此类作品:

double x = (info.eventPosition.game - position).x - dragDeltaPosition.x;
double y = (info.eventPosition.game - position).y - dragDeltaPosition.y;

如果有更好的方法请告诉我。谢谢

您必须查看 delta,它是从上一个 onDragUpdate 到当前

的向量。

  @override
  bool onDragUpdate(DragUpdateInfo info) {
    // You can use info.delta.game.normalized here too if you don't care
    // about the length of the directional vector.
    dragDirectionVector = info.delta.game;
  }