follow method

void follow(
  1. ReadOnlyPositionProvider target, {
  2. double maxSpeed = double.infinity,
  3. bool horizontalOnly = false,
  4. bool verticalOnly = false,
  5. bool snap = false,
})

Makes the viewfinder follow the given target.

The target here can be any read-only PositionProvider. For example, a PositionComponent is the most common choice of target. Alternatively, you can use PositionProviderImpl to construct the target dynamically.

This method adds a FollowBehavior to the viewfinder. If there is another FollowBehavior currently applied to the viewfinder, it will be removed first.

Parameters maxSpeed, horizontalOnly and verticalOnly have the same meaning as in the FollowBehavior.new constructor.

If snap is true, then the viewfinder's starting position will be set to the target's current location. If snap is false, then the viewfinder will move from its current position to the target's position at the given speed.

Implementation

void follow(
  ReadOnlyPositionProvider target, {
  double maxSpeed = double.infinity,
  bool horizontalOnly = false,
  bool verticalOnly = false,
  bool snap = false,
}) {
  stop();
  viewfinder.add(
    FollowBehavior(
      target: target,
      owner: viewfinder,
      maxSpeed: maxSpeed,
      horizontalOnly: horizontalOnly,
      verticalOnly: verticalOnly,
    ),
  );
  if (snap) {
    viewfinder.position = target.position;
  }
}