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 - geom/Polygon.js, line 24

Members

area :number

The area of this Polygon.

Source - geom/Polygon.js, line 29

closed :boolean

Is the Polygon closed or not?

Source - geom/Polygon.js, line 45

points :Array.<Phaser.Point>

This method is deprecated and should not be used. It may be removed in the future.

Sets and modifies the points of this polygon.

See setTo for the different kinds of arrays formats that can be assigned. The array of vertex points.

Type:
Deprecated:
  • Use `setTo`.
Source - geom/Polygon.js, line 261

type :number

The base object type.

Source - geom/Polygon.js, line 50

Methods

clone(output) → {Phaser.Polygon}

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 Polygon)

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

Returns:

The cloned (output) polygon object.

Source - geom/Polygon.js, line 100

contains(x, y) → {boolean}

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.

Returns:
boolean -

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

Source - geom/Polygon.js, line 125

flatten() → {Phaser.Polygon}

Flattens this Polygon so the points are a sequence of numbers. Any Point objects found are removed and replaced with two numbers.

Returns:

This Polygon object

Source - geom/Polygon.js, line 86

setTo(points) → {Phaser.Polygon}

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, ...]
  • 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.

Returns:

This Polygon object

Source - geom/Polygon.js, line 158

toNumberArray(output) → {array}

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.

Returns:
array -

The flattened array.

Source - geom/Polygon.js, line 56
Phaser Copyright © 2012-2015 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-alpha10 on Mon Mar 23 2015 23:44:09 GMT+0000 (GMT Standard Time) using the DocStrap template.