update method

  1. @override
void update(
  1. double dt
)
override

This method is called periodically by the game engine to request that your component updates itself.

The time dt in seconds (with microseconds precision provided by Flutter) since the last update cycle. This time can vary according to hardware capacity, so make sure to update your state considering this. All components in the tree are always updated by the same amount. The time each one takes to update adds up to the next update cycle.

Implementation

@override
void update(double dt) {
  _tempDelta.setValues(
    verticalOnly ? 0 : target.position.x - owner.position.x,
    horizontalOnly ? 0 : target.position.y - owner.position.y,
  );

  final distance = _tempDelta.length;
  final deltaOffset = _speed * dt;
  if (distance > deltaOffset) {
    _tempDelta.scale(deltaOffset / distance);
  }
  if (_tempDelta.x != 0 || _tempDelta.y != 0) {
    owner.position = _tempDelta..add(owner.position);
  }
}