Class: Polygon

Phaser. Polygon

new Polygon(points)

Creates a new Polygon.

The points can be set from a variety of formats:

  • 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, ...]
  • As separate Point arguments: setTo(new Phaser.Point(x1, y1), ...)
  • As separate objects with public x/y properties arguments: setTo(obj1, obj2, ...)
  • As separate arguments representing point coordinates: setTo(x1,y1, x2,y2, ...)
Parameters:
Name Type Description
points Array.<Phaser.Point> | Array.<number> | Phaser.Point | number

The points to set.

Source:
src/geom/Polygon.js line 24

Members

area : number

The area of this Polygon.

Type:
  • number
Source:
src/geom/Polygon.js line 29

closed : boolean

Is the Polygon closed or not?

Type:
  • boolean
Source:
src/geom/Polygon.js line 45

flattened : boolean

Has this Polygon been flattened by a call to Polygon.flatten ?

Type:
  • boolean
Source:
src/geom/Polygon.js line 50

<readonly> points : Array.<Phaser.Point>

The points of this polygon.

You can modify these with setTo. The array of vertex points.

Type:
Source:
src/geom/Polygon.js line 286

type : number

The base object type.

Type:
  • number
Source:
src/geom/Polygon.js line 55

Methods

clone( [output])

Creates a copy of the given Polygon. This is a deep clone, the resulting copy contains new Phaser.Point objects

Parameters:
Name Type Argument Default Description
output Phaser.Polygon <optional>
(new Phaser.Polygon)

The polygon to update. If not specified a new polygon will be created.

Source:
src/geom/Polygon.js line 106
Returns:

The cloned (output) polygon object.

Type
Phaser.Polygon

contains(x, y)

Checks whether the x and y coordinates are contained within this polygon.

Parameters:
Name Type Description
x number

The X value of the coordinate to test.

y number

The Y value of the coordinate to test.

Source:
src/geom/Polygon.js line 130
Returns:

True if the coordinates are within this polygon, otherwise false.

Type
boolean

flatten()

Flattens this Polygon so the points are a sequence of numbers. Any Point objects found are removed and replaced with two numbers. Also sets the Polygon.flattened property to true.

Source:
src/geom/Polygon.js line 89
Returns:

This Polygon object

Type
Phaser.Polygon

setTo(points)

Sets this Polygon to the given points.

The points can be set from a variety of formats:

  • 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], ...]
  • As separate Point arguments: setTo(new Phaser.Point(x1, y1), ...)
  • As separate objects with public x/y properties arguments: setTo(obj1, obj2, ...)
  • As separate arguments representing point coordinates: setTo(x1,y1, x2,y2, ...)

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

Parameters:
Name Type Description
points Array.<Phaser.Point> | Array.<number> | Phaser.Point | number

The points to set.

Source:
src/geom/Polygon.js line 180
Returns:

This Polygon object

Type
Phaser.Polygon

toNumberArray( [output])

Export the points as an array of flat numbers, following the sequence [ x,y, x,y, x,y ]

Parameters:
Name Type Argument Description
output array <optional>

The array to append the points to. If not specified a new array will be created.

Source:
src/geom/Polygon.js line 60
Returns:

The flattened array.

Type
array

phaser-ce@2.20.0 is on GitHub and NPM

Documentation generated by JSDoc 3.6.7 on 2022-12-10 using Tomorrow.