moveToPositionAnimated method

void moveToPositionAnimated(
  1. Vector2 position, {
  2. double? zoom,
  3. double? angle,
  4. VoidCallback? finish,
  5. Duration? duration,
  6. Curve curve = Curves.decelerate,
})

Implementation

void moveToPositionAnimated(
  Vector2 position, {
  double? zoom,
  double? angle,
  VoidCallback? finish,
  Duration? duration,
  Curve curve = Curves.decelerate,
}) {
  if ((zoom != null && zoom <= 0.0) || _isMoving) return;
  this.target = null;
  _isMoving = true;

  double newZoom = zoom ?? this.zoom;
  double newAngle = angle ?? this.angle;
  double diffX = this.position.x - position.x;
  double diffY = this.position.y - position.y;
  double originX = this.position.x;
  double originY = this.position.y;

  double diffZoom = this.zoom - newZoom;
  double initialZoom = this.zoom;

  double diffAngle = this.angle - newAngle;
  double originAngle = this.angle;

  gameRef.getValueGenerator(
    duration ?? Duration(seconds: 1),
    onChange: (value) {
      snapTo(
        Vector2(
          originX - (diffX * value),
          originY - (diffY * value),
        ),
      );

      this.zoom = initialZoom - (diffZoom * value);
      this.angle = originAngle - (diffAngle * value);

      if (this.moveOnlyMapArea) {
        _keepInMapArea();
      }
    },
    onFinish: () {
      _isMoving = false;
      finish?.call();
    },
    curve: curve,
  ).start();
}