seeComponent method
Shape?
seeComponent(
- GameComponent component, {
- required dynamic observed(),
- VoidCallback? notObserved,
- double radiusVision = 32,
- double? visionAngle,
- double angle = 3.14159,
This method we notify when detect the component when enter in radiusVision configuration
Method that bo used in update method.
visionAngle in radians
angle in radians.
Implementation
Shape? seeComponent(
GameComponent component, {
required Function(GameComponent) observed,
VoidCallback? notObserved,
double radiusVision = 32,
double? visionAngle,
double angle = 3.14159,
}) {
if (component.isRemoving) {
notObserved?.call();
return _currentShape = null;
}
String key = '$radiusVision/$visionAngle/$angle';
PolygonShape shape;
if (_polygonCache.containsKey(key)) {
shape = _polygonCache[key]!;
shape.position = center;
} else {
shape = _buildShape(radiusVision, visionAngle, angle, center);
_polygonCache[key] = shape;
}
if (component.isRemoving) {
notObserved?.call();
}
final rect = component.rectConsideringCollision;
final otherShape = RectangleShape(
rect.sizeVector2,
position: rect.positionVector2,
);
if (shape.isCollision(otherShape)) {
observed(component);
} else {
notObserved?.call();
}
return _currentShape = shape;
}