Class: Polygon

Phaser.Geom. Polygon

[description]


new Polygon( [points])

Parameters:
Name Type Argument Description
points Array.<Phaser.Geom.Point> <optional>

[description]

Since: 3.0.0
Source: src/geom/polygon/Polygon.js (Line 11)

Members


area :number

The area of this Polygon.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/geom/polygon/Polygon.js (Line 28)

points :Array.<Phaser.Geom.Point>

An array of number pair objects that make up this polygon. I.e. [ {x,y}, {x,y}, {x,y} ]

Type:
Since: 3.0.0
Source: src/geom/polygon/Polygon.js (Line 38)

Methods


<static> Clone(polygon)

[description]

Parameters:
Name Type Description
polygon Phaser.Geom.Polygon

[description]

Since: 3.0.0
Source: src/geom/polygon/Clone.js (Line 9)
Returns:

[description]

Type
Phaser.Geom.Polygon

<static> Contains(polygon, x, y)

Checks if a point is within the bounds of a Polygon.

Parameters:
Name Type Description
polygon Phaser.Geom.Polygon

The Polygon to check against.

x number

The X coordinate of the point to check.

y number

The Y coordinate of the point to check.

Since: 3.0.0
Source: src/geom/polygon/Contains.js (Line 10)
Returns:

true if the point is within the bounds of the Polygon, otherwise false.

Type
boolean

<static> ContainsPoint(polygon, point)

[description]

Parameters:
Name Type Description
polygon Phaser.Geom.Polygon

[description]

point Phaser.Geom.Point

[description]

Since: 3.0.0
Source: src/geom/polygon/ContainsPoint.js (Line 9)
Returns:

[description]

Type
boolean

<static> GetAABB(polygon [, out])

[description]

Parameters:
Name Type Argument Description
polygon Phaser.Geom.Polygon

[description]

out Phaser.Geom.Rectangle | object <optional>

[description]

Since: 3.0.0
Source: src/geom/polygon/GetAABB.js (Line 9)
Returns:

[description]

Type
Phaser.Geom.Rectangle | object

<static> GetNumberArray(polygon [, output])

Stores all of the points of a Polygon into a flat array of numbers following the sequence [ x,y, x,y, x,y ],
i.e. each point of the Polygon, in the order it's defined, corresponds to two elements of the resultant
array for the point's X and Y coordinate.

Parameters:
Name Type Argument Description
polygon Phaser.Geom.Polygon

The Polygon whose points to export.

output array | Array.<number> <optional>

An array to which the points' coordinates should be appended.

Since: 3.0.0
Source: src/geom/polygon/GetNumberArray.js (Line 9)
Returns:

The modified output array, or a new array if none was given.

Type
array | Array.<number>

<static> GetPoints(polygon, quantity [, stepRate] [, output])

Returns an array of Point objects containing the coordinates of the points around the perimeter of the Polygon,
based on the given quantity or stepRate values.

Parameters:
Name Type Argument Description
polygon Phaser.Geom.Polygon

The Polygon to get the points from.

quantity integer

The amount of points to return. If a falsey value the quantity will be derived from the stepRate instead.

stepRate number <optional>

Sets the quantity by getting the perimeter of the Polygon and dividing it by the stepRate.

output array <optional>

An array to insert the points in to. If not provided a new array will be created.

Since: 3.12.0
Source: src/geom/polygon/GetPoints.js (Line 11)
Returns:

An array of Point objects pertaining to the points around the perimeter of the Polygon.

Type
Array.<Phaser.Geom.Point>

<static> Perimeter(polygon)

Returns the perimeter of the given Polygon.

Parameters:
Name Type Description
polygon Phaser.Geom.Polygon

The Polygon to get the perimeter of.

Since: 3.12.0
Source: src/geom/polygon/Perimeter.js (Line 10)
Returns:

The perimeter of the Polygon.

Type
number

<static> Reverse(polygon)

[description]

Parameters:
Name Type Description
polygon Phaser.Geom.Polygon

[description]

Since: 3.0.0
Source: src/geom/polygon/Reverse.js (Line 7)
Returns:

[description]

Type
Phaser.Geom.Polygon

<static> Smooth(polygon)

Takes a Polygon object and applies Chaikin's smoothing algorithm on its points.

Parameters:
Name Type Description
polygon Phaser.Geom.Polygon

The polygon to be smoothed. The polygon will be modified in-place and returned.

Since: 3.13.0
Source: src/geom/polygon/Smooth.js (Line 16)
Returns:

The input polygon.

Type
Phaser.Geom.Polygon

calculateArea()

Calculates the area of the Polygon. This is available in the property Polygon.area

Since: 3.0.0
Source: src/geom/polygon/Polygon.js (Line 144)
Returns:

The area of the polygon.

Type
number

contains(x, y)

Check to see if the Polygon contains the given x / y coordinates.

Parameters:
Name Type Description
x number

The x coordinate to check within the polygon.

y number

The y coordinate to check within the polygon.

Since: 3.0.0
Source: src/geom/polygon/Polygon.js (Line 53)
Returns:

true if the coordinates are within the polygon, otherwise false.

Type
boolean

getPoints(quantity [, stepRate] [, output])

Returns an array of Point objects containing the coordinates of the points around the perimeter of the Polygon,
based on the given quantity or stepRate values.

Parameters:
Name Type Argument Description
quantity integer

The amount of points to return. If a falsey value the quantity will be derived from the stepRate instead.

stepRate number <optional>

Sets the quantity by getting the perimeter of the Polygon and dividing it by the stepRate.

output array <optional>

An array to insert the points in to. If not provided a new array will be created.

Since: 3.12.0
Source: src/geom/polygon/Polygon.js (Line 183)
Returns:

An array of Point objects pertaining to the points around the perimeter of the Polygon.

Type
Array.<Phaser.Geom.Point>

setTo(points)

Sets this Polygon to the given points.

The points can be set from a variety of formats:

  • A string containing paired values separated by a single space: '40 0 40 20 100 20 100 80 40 80 40 100 0 50'
  • An array of Point objects: [new Phaser.Point(x1, y1), ...]
  • An array of objects with public x/y properties: [obj1, obj2, ...]
  • An array of paired numbers that represent point coordinates: [x1,y1, x2,y2, ...]
  • An array of arrays with two elements representing x/y coordinates: [[x1, y1], [x2, y2], ...]

setTo may also be called without any arguments to remove all points.

Parameters:
Name Type Description
points array

[description]

Since: 3.0.0
Source: src/geom/polygon/Polygon.js (Line 69)
Returns:

This Polygon object.

Type
Phaser.Geom.Polygon