follow method

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

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

@override
void follow(
  ReadOnlyPositionProvider target, {
  double maxSpeed = double.infinity,
  bool horizontalOnly = false,
  bool verticalOnly = false,
  bool snap = false,
}) {
  stop();
  viewfinder.add(
    MyFollowBehavior(
      target: target,
      targetSize: _getTargetSize(target),
      maxSpeed: config.speed,
      movementWindow: config.movementWindow,
      horizontalOnly: horizontalOnly,
      verticalOnly: verticalOnly,
    ),
  );
  if (snap) {
    viewfinder.position = target.position;
  }
}