PolygonHitbox.fromPath constructor

PolygonHitbox.fromPath(
  1. Path path, {
  2. int contour = 0,
  3. double sampling = 1.0,
  4. double? tolerance,
  5. Vector2? position,
  6. double? angle,
  7. Anchor? anchor,
  8. bool isSolid = false,
  9. CollisionType collisionType = CollisionType.active,
})

With this constructor you create a PolygonHitbox from the given contour (the first by default) of a Path.

A polygon only has straight edges, so the curves of the path are approximated. The contour is sampled every sampling along its length, and the samples that are not needed to stay within about half of the sampling of the contour are left out. Higher values give fewer vertices, which makes the collision detection cheaper, and a looser fit, while straight stretches and the corners between them are exact whatever the sampling is. The given tolerance decides what samples to discard: by default, its value is half the sampling.

See PathMetricExtension.walkContour for the details of the sampling and tolerance parameters.

Implementation

PolygonHitbox.fromPath(
  super.path, {
  super.contour,
  super.sampling,
  super.tolerance,
  super.position,
  super.angle,
  super.anchor,
  super.isSolid,
  CollisionType collisionType = CollisionType.active,
}) : super.fromPath() {
  this.collisionType = collisionType;
}