PolygonComponent constructor
PolygonComponent(})
With this constructor you create your PolygonComponent from positions in
anywhere in the 2d-space. It will automatically calculate the size
of
the Polygon (the bounding box) if no size it given.
NOTE: Always define your polygon in a counter-clockwise fashion (in the
screen coordinate system).
Implementation
PolygonComponent(
this._vertices, {
Vector2? position,
Vector2? size,
Vector2? scale,
double? angle,
Anchor? anchor,
int? priority,
Paint? paint,
bool? shrinkToBounds,
}) : assert(
_vertices.length > 2,
'Number of vertices are too few to create a polygon',
),
shrinkToBounds = shrinkToBounds ?? size == null,
manuallyPositioned = position != null,
super(
position: position,
size: size,
scale: scale,
angle: angle,
anchor: anchor,
priority: priority,
paint: paint,
) {
refreshVertices(newVertices: _vertices);
final verticesLength = _vertices.length;
_globalVertices = List.generate(
verticesLength,
(_) => Vector2.zero(),
growable: false,
);
_lineSegments = List.generate(
verticesLength,
(_) => LineSegment.zero(),
growable: false,
);
}