moveToTargetAnimated method
void
moveToTargetAnimated(
- GameComponent target, {
- double zoom = 1,
- double angle = 0,
- VoidCallback? finish,
- Duration? duration,
- Curve curve = Curves.decelerate,
Implementation
void moveToTargetAnimated(
GameComponent target, {
double zoom = 1,
double angle = 0,
VoidCallback? finish,
Duration? duration,
Curve curve = Curves.decelerate,
}) {
if (zoom <= 0.0 || _isMoving) return;
config.target = null;
_isMoving = true;
double originX = this.position.dx;
double originY = this.position.dy;
double diffZoom = config.zoom - zoom;
double initialZoom = config.zoom;
double diffAngle = config.angle - angle;
double originAngle = config.angle;
gameRef.getValueGenerator(
duration ?? Duration(seconds: 1),
onChange: (value) {
double diffX = originX - target.position.center.dx;
double diffY = originY - target.position.center.dy;
this.position = position.copyWith(x: originX - (diffX * value));
this.position = position.copyWith(y: originY - (diffY * value));
config.zoom = initialZoom - (diffZoom * value);
config.angle = originAngle - (diffAngle * value);
if (config.moveOnlyMapArea) {
_keepInMapArea();
}
},
onFinish: () {
config.target = target;
_isMoving = false;
finish?.call();
},
curve: curve,
).start();
}