Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Geom . Point

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Geom . Point

Defines a Point in 2D space, with an x and y component.

Constructor:

new Point([x], [y])

Parameters:

name type arguments Default description
x number <optional> 0

The x coordinate of this Point.

y number <optional> x

The y coordinate of this Point.

Since: 3.0.0
Source: src/geom/point/Point.js (Line 10)

Members

<readonly> type: number
Focus
Focus

Description:

The geometry constant type of this object: GEOM_CONST.POINT. Used for fast type comparisons.

Type:
number
Since: 3.19.0
Source: src/geom/point/Point.js (Line 31)
Focus
Focus
x: number
Focus
Focus

Description:

The x coordinate of this Point.

Type:
number
Default: 0
Since: 3.0.0
Source: src/geom/point/Point.js (Line 42)
Focus
Focus
y: number
Focus
Focus

Description:

The y coordinate of this Point.

Type:
number
Default: 0
Since: 3.0.0
Source: src/geom/point/Point.js (Line 52)
Focus
Focus

Methods

setTo([x], [y])
Focus
Focus

Description:

Set the x and y coordinates of the point to the given values.

Parameters:

name type arguments Default description
x number <optional> 0

The x coordinate of this Point.

y number <optional> x

The y coordinate of this Point.

Returns:
Description:

This Point object.

Examples:
Since: 3.0.0
Source: src/geom/point/Point.js (Line 63)
Focus
Focus
<static> Ceil(point)
Focus
Focus

Description:

Apply Math.ceil() to each coordinate of the given Point.

Parameters:

name type description
point Phaser.Geom.Point

The Point to ceil.

Returns:
Description:

The Point with Math.ceil() applied to its coordinates.

Examples:
Since: 3.0.0
Source: src/geom/point/Ceil.js (Line 7)
Focus
Focus
<static> Clone(source)
Focus
Focus

Description:

Clone the given Point.

Parameters:

name type description
source Phaser.Geom.Point

The source Point to clone.

Returns:
Description:

The cloned Point.

Examples:
Since: 3.0.0
Source: src/geom/point/Clone.js (Line 9)
Focus
Focus
<static> CopyFrom(source, dest)
Focus
Focus

Description:

Copy the values of one Point to a destination Point.

Parameters:

name type description
source Phaser.Geom.Point

The source Point to copy the values from.

dest Phaser.Geom.Point

The destination Point to copy the values to.

Returns:
Description:

The destination Point.

Examples:
Since: 3.0.0
Source: src/geom/point/CopyFrom.js (Line 7)
Focus
Focus
<static> Equals(point, toCompare)
Focus
Focus

Description:

A comparison of two Point objects to see if they are equal.

Parameters:

name type description
point Phaser.Geom.Point

The original Point to compare against.

toCompare Phaser.Geom.Point

The second Point to compare.

Returns:
Description:

Returns true if the both Point objects are equal.

Type:
  • boolean
Examples:
Since: 3.0.0
Source: src/geom/point/Equals.js (Line 7)
Focus
Focus
<static> Floor(point)
Focus
Focus

Description:

Apply Math.ceil() to each coordinate of the given Point.

Parameters:

name type description
point Phaser.Geom.Point

The Point to floor.

Returns:
Description:

The Point with Math.floor() applied to its coordinates.

Examples:
Since: 3.0.0
Source: src/geom/point/Floor.js (Line 7)
Focus
Focus
<static> GetCentroid(points, [out])
Focus
Focus

Description:

Get the centroid or geometric center of a plane figure (the arithmetic mean position of all the points in the figure). Informally, it is the point at which a cutout of the shape could be perfectly balanced on the tip of a pin.

Parameters:

name type arguments description
points Array.<Phaser.Types.Math.Vector2Like>

An array of Vector2Like objects to get the geometric center of.

out Phaser.Geom.Point <optional>

A Point object to store the output coordinates in. If not given, a new Point instance is created.

Returns:
Description:

A Point object representing the geometric center of the given points.

Examples:
Since: 3.0.0
Focus
Focus
<static> GetMagnitude(point)
Focus
Focus

Description:

Calculate the magnitude of the point, which equivalent to the length of the line from the origin to this point.

Parameters:

name type description
point Phaser.Geom.Point

The point to calculate the magnitude for

Returns:
Description:

The resulting magnitude

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<static> GetMagnitudeSq(point)
Focus
Focus

Description:

Calculates the square of magnitude of given point.(Can be used for fast magnitude calculation of point)

Parameters:

name type description
point Phaser.Geom.Point

Returns square of the magnitude/length of given point.

Returns:
Description:

Returns square of the magnitude of given point.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<static> GetRectangleFromPoints(points, [out])
Focus
Focus

Description:

Calculates the Axis Aligned Bounding Box (or aabb) from an array of points.

Parameters:

name type arguments description
points Array.<Phaser.Types.Math.Vector2Like>

An array of Vector2Like objects to get the AABB from.

out Phaser.Geom.Rectangle <optional>

A Rectangle object to store the results in. If not given, a new Rectangle instance is created.

Returns:
Description:

A Rectangle object holding the AABB values for the given points.

Examples:
Since: 3.0.0
Focus
Focus
<static> Interpolate(pointA, pointB, [t], [out])
Focus
Focus

Description:

Returns the linear interpolation point between the two given points, based on t.

Parameters:

name type arguments description
pointA Phaser.Geom.Point

The starting Point for the interpolation.

pointB Phaser.Geom.Point

The target Point for the interpolation.

t number <optional>

The amount to interpolate between the two points. Generally, a value between 0 (returns the starting Point) and 1 (returns the target Point). If omitted, 0 is used.

out object | Phaser.Geom.Point <optional>

An optional Point object whose x and y values will be set to the result of the interpolation (can also be any object with x and y properties). If omitted, a new Point created and returned.

Returns:
Description:

Either the object from the out argument with the properties x and y set to the result of the interpolation or a newly created Point object.

Type:
Examples:
Since: 3.0.0
Focus
Focus
<static> Invert(point)
Focus
Focus

Description:

Swaps the X and the Y coordinate of a point.

Parameters:

name type description
point Phaser.Geom.Point

The Point to modify.

Returns:
Description:

The modified point.

Examples:
Since: 3.0.0
Source: src/geom/point/Invert.js (Line 7)
Focus
Focus
<static> Negative(point, [out])
Focus
Focus

Description:

Inverts a Point's coordinates.

Parameters:

name type arguments description
point Phaser.Geom.Point

The Point to invert.

out Phaser.Geom.Point <optional>

The Point to return the inverted coordinates in.

Returns:
Description:

The modified out Point, or a new Point if none was provided.

Examples:
Since: 3.0.0
Source: src/geom/point/Negative.js (Line 9)
Focus
Focus
<static> Project(pointA, pointB, [out])
Focus
Focus

Description:

Calculates the vector projection of pointA onto the nonzero pointB. This is the orthogonal projection of pointA onto a straight line parallel to pointB.

Parameters:

name type arguments description
pointA Phaser.Geom.Point

Point A, to be projected onto Point B.

pointB Phaser.Geom.Point

Point B, to have Point A projected upon it.

out Phaser.Geom.Point <optional>

The Point object to store the position in. If not given, a new Point instance is created.

Returns:
Description:

A Point object holding the coordinates of the vector projection of pointA onto pointB.

Examples:
Since: 3.0.0
Source: src/geom/point/Project.js (Line 10)
Focus
Focus
<static> ProjectUnit(pointA, pointB, [out])
Focus
Focus

Description:

Calculates the vector projection of pointA onto the nonzero pointB. This is the orthogonal projection of pointA onto a straight line paralle to pointB.

Parameters:

name type arguments description
pointA Phaser.Geom.Point

Point A, to be projected onto Point B. Must be a normalized point with a magnitude of 1.

pointB Phaser.Geom.Point

Point B, to have Point A projected upon it.

out Phaser.Geom.Point <optional>

The Point object to store the position in. If not given, a new Point instance is created.

Returns:
Description:

A unit Point object holding the coordinates of the vector projection of pointA onto pointB.

Examples:
Since: 3.0.0
Focus
Focus
<static> SetMagnitude(point, magnitude)
Focus
Focus

Description:

Changes the magnitude (length) of a two-dimensional vector without changing its direction.

Parameters:

name type description
point Phaser.Geom.Point

The Point to treat as the end point of the vector.

magnitude number

The new magnitude of the vector.

Returns:
Description:

The modified Point.

Examples:
Since: 3.0.0
Focus
Focus