followVector2 method

void followVector2(
  1. Vector2 vector2, {
  2. Anchor relativeOffset = Anchor.center,
  3. Rect? worldBounds,
})

Immediately snaps the camera to start following vector2.

This means that the camera will move so that the position vector is in a fixed position on the screen. That position is determined by a fraction of screen size defined by relativeOffset (default to the center). worldBounds can be optionally set to add boundaries to how far the camera is allowed to move.

Implementation

void followVector2(
  Vector2 vector2, {
  Anchor relativeOffset = Anchor.center,
  Rect? worldBounds,
}) {
  follow = vector2;
  if (worldBounds != null) {
    this.worldBounds = worldBounds;
  }
  _targetRelativeOffset.setFrom(relativeOffset.toVector2());
  _currentRelativeOffset.setFrom(_targetRelativeOffset);
}