update method
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) {
var delta = (target.position + (targetSize / 2)) - owner.position;
if (horizontalOnly && !verticalOnly) {
delta = _moveHorizontal(delta);
} else if (!horizontalOnly && verticalOnly) {
delta = _moveVertical(delta);
} else {
delta = _moveHorizontal(delta);
delta = _moveVertical(delta);
}
if (delta.isZero()) return;
if (delta.length <= maxSpeed * dt) {
owner.position = delta..add(owner.position);
} else {
owner.position = owner.position.clone()
..lerp(owner.position + delta, dt * maxSpeed);
}
}