PolygonComponent.fromPoints constructor

PolygonComponent.fromPoints(
  1. List<Vector2> points, {
  2. Paint? paint,
  3. Vector2? position,
  4. Vector2? size,
  5. Vector2? scale,
  6. double? angle,
  7. Anchor? anchor,
  8. int? priority,
})

Instead of using vertices that are in relation to the size of the component you can use this factory with absolute points which will set the position and size of the component and calculate the normalized vertices.

Implementation

factory PolygonComponent.fromPoints(
  List<Vector2> points, {
  Paint? paint,
  Vector2? position,
  Vector2? size,
  Vector2? scale,
  double? angle,
  Anchor? anchor,
  int? priority,
}) {
  final polygon = Polygon(points);
  final anchorPosition = position ??
      Anchor.center.toOtherAnchorPosition(
        polygon.position,
        anchor ?? Anchor.topLeft,
        size ?? polygon.size,
      );
  return PolygonComponent(
    normalizedVertices: polygon.normalizedVertices,
    paint: paint,
    position: anchorPosition,
    size: size ?? polygon.size,
    scale: scale,
    angle: angle,
    anchor: anchor,
    priority: priority,
  );
}