Skip to main content

Polygons

Arc

Arc([arc, radius, orbit], anchor?=, cap?, pos?, angle?) -> shape

Returns a Polygon representing an arc. An arc is curved line that follows the edge of a circle. This can be used by functions like PolygonCollider or PolygonSprite.

  • arc (Number): The angular width of the arc in radians. For example, 0.25rev would make an arc that covered one quarter of a circle.
  • radius (Number): The half-width of the line that you would like to draw.
  • orbit (Number): The distance from the line to the focal point of the arc. A smaller number makes a tighter arc.
  • cap (Boolean): Whether the ends of the arc are rounded.
  • anchor (Number): If set to 1 (the default), the center of the arc's line will be placed at the origin. If set to 0, the focal point of the arc will be placed at the origin.
  • pos (Vector): offsets the arc from the origin by this amount.
  • angle (Number): rotates the arc by this angle, specified in radians.

Capsule

Capsule([extent, radius], pos?=, angle?) -> shape

Returns a polygon representing a capsule. A capsule is a single horizontal line segment with rounded ends.

  • pos (Vector): Offsets the position of the capsule by the given vector.
  • angle (Number): Rotates the capsule by the given angle in radians.

A capsule has two focal points, each in the center of its two rounded ends.

  • extent (Number): Defines the distance from the center of the capsule to the two focal points. In other words, defines the half-width of the capsule.
  • radius (Number): Defines the distance from a focal point to the edge of the capsule. In other words, defines the half-height of the capsule.

Circle

Circle([radius], pos?=) -> shape

Returns a polygon representing a circle.

  • radius controls the width of the circle. It is the distance from the center of the circle to the edge of the circle.
  • pos sets the position of the circle.

Equilateral

Equilateral(numPoints, [radius], pos?=, angle?) -> shape

Returns a polygon representing an equilateral polygon. An equilateral polygon is a regular polygon with all sides and angles equal.

  • numPoints is the number of points in the polygon. If it is less than 3, the polygon will be a circle.
  • radius controls the width of the polygon. It is the distance from the center of the polygon to the edge of the polygon.
  • pos and angle sets the position and angle of the polygon respectively.

Line

Line(points, [radius], cap?=, headCap?, tailCap?, headTilt?, tailTilt?) -> shape

Returns a line polygon.

  • points is an array of points that form the line. Each point will be connected to the next point in the array.
  • radius controls the radius of the line. If it is a single number, the line will have a constant radius. If it is an array of two numbers, the line's radius will be tapered from the first number to the second number. If there are more than two numbers provided, only the first and last number will be used.
  • If cap is true, then both of the line's ends will be rounded.
  • If headCap is true, then the first point in the line will be rounded.
  • If tailCap is true, then the last point in the line will be rounded.
  • headTilt and tailTilt control the tilt of the line's ends. A value of 0 will make the line's ends perpendicular to the line, whereas a non-zero value will tilt the line's ends by that amount.

Polygon

Polygon(points, border?=) -> shape

Returns a polygon shape.

  • points (Array): an array of points that form the perimeter of the polygon. Each point will be connected to the next point in the array, and then the last point will be connected back onto the first point.

Rectangle

Rectangle(pos?=, angle?, width?, height?, [extent?, radius?]) -> shape

Returns a polygon representing a rectangle.

  • pos (Vector): Offsets the position of this rectangle by the given vector.
  • angle (Number): Rotates the rectangle by the given angle in radians.

The natural way to specify the size of a rectangle is to use the following two arguments:

  • width (Number): The width of the rectangle.
  • height (Number): The height of the rectangle.

These parameters should not be used as they are buggy and are only being kept around for legacy reasons:

  • extent (Number): The half-width of the rectangle.
  • radius (Number): The half-height of the rectangle.

Sector

Sector(arc, [radius], pos?=, angle?) -> shape

Returns a polygon representing a sector. A sector is a portion of a circle enclosed by two radii and an arc.

  • arc is the angular width of the sector in radians.
  • radius controls the size of the sector. It is the distance from the center of the sector's circle to the edge of the sector.
  • pos and angle sets the position and angle of the sector respectively.