new Point( [x] [, y])
A Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
The following code creates a point at (0,0):
var myPoint = new Phaser.Point();
You can also use them as 2D Vectors and you'll find different vector related methods in this class.
Parameters:
| Name | Type | Argument | Default | Description |
|---|---|---|---|---|
x |
number |
<optional> |
0 | The horizontal position of this Point. |
y |
number |
<optional> |
0 | The vertical position of this Point. |
- Source:
- src/geom/Point.js line 18
Members
-
<readonly> type : number
-
The const type of this object.
Type:
- number
- Source:
- src/geom/Point.js line 37
-
x : number
-
The x value of the point.
Type:
- number
- Source:
- src/geom/Point.js line 26
-
y : number
-
The y value of the point.
Type:
- number
- Source:
- src/geom/Point.js line 31
Methods
-
<static> add(a, b [, out])
-
Adds the coordinates of two points together to create a new point.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 525
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> angle(a, b)
-
Returns the angle between two Point objects.
Parameters:
Name Type Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
- Source:
- src/geom/Point.js line 619
Returns:
The angle between the two Points.
- Type
- number
-
<static> centroid(points [, out])
-
Calculates centroid (or midpoint) from an array of points. If only one point is provided, that point is returned.
Parameters:
Name Type Argument Description pointsArray.<Phaser.Point> The array of one or more points.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 866
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> distance(a, b [, round])
-
Returns the euclidian distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties).
Parameters:
Name Type Argument Default Description aobject The target object. Must have visible x and y properties that represent the center of the object.
bobject The target object. Must have visible x and y properties that represent the center of the object.
roundboolean <optional>
false Round the distance to the nearest integer.
- Source:
- src/geom/Point.js line 718
Returns:
The distance between this Point object and the destination Point object.
- Type
- number
-
<static> divide(a, b [, out])
-
Divides the coordinates of two points to create a new point.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 585
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> equals(a, b)
-
Determines whether the two given Point objects are equal. They are considered equal if they have the same x and y values.
Parameters:
Name Type Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
- Source:
- src/geom/Point.js line 605
Returns:
A value of true if the Points are equal, otherwise false.
- Type
- boolean
-
<static> interpolate(a, b, f [, out])
-
Interpolates the two given Points, based on the
fvalue (between 0 and 1) and returns a new Point.Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
fnumber The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 668
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> isPoint()
-
Tests a Point or Point-like object.
- Source:
- src/geom/Point.js line 939
Returns:
- True if the object has numeric x and y properties.
- Type
- boolean
-
<static> multiply(a, b [, out])
-
Multiplies the coordinates of two points to create a new point.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 565
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> multiplyAdd(a, b, s [, out])
-
Adds two 2D Points together and multiplies the result by the given scalar.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
snumber The scaling value.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 650
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> negative(a [, out])
-
Creates a negative Point.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 634
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> normalize(a [, out])
-
Normalize (make unit length) a Point.
Parameters:
Name Type Argument Description aPhaser.Point The Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 798
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> normalRightHand(a [, out])
-
Right-hand normalize (make unit length) a Point.
Parameters:
Name Type Argument Description aPhaser.Point The Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 782
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> parse(obj [, xProp] [, yProp])
-
Parses an object for x and/or y properties and returns a new Phaser.Point with matching values. If the object doesn't contain those properties a Point with x/y of zero will be returned.
Parameters:
Name Type Argument Default Description objobject The object to parse.
xPropstring <optional>
'x' The property used to set the Point.x value.
yPropstring <optional>
'y' The property used to set the Point.y value.
- Source:
- src/geom/Point.js line 907
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> perp(a [, out])
-
Return a perpendicular vector (90 degrees rotation)
Parameters:
Name Type Argument Description aPhaser.Point The Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 686
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> project(a, b [, out])
-
Project two Points onto another Point.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 734
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> projectUnit(a, b [, out])
-
Project two Points onto a Point of unit length.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 758
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> rotate(a, x, y, angle [, asDegrees] [, distance])
-
Rotates a Point object, or any object with exposed x/y properties, around the given coordinates by the angle specified. If the angle between the point and coordinates was 45 deg and the angle argument is 45 deg then the resulting angle will be 90 deg, as the angle argument is added to the current angle.
The distance allows you to specify a distance constraint for the rotation between the point and the coordinates. If none is given the distance between the two is calculated and used.
Parameters:
Name Type Argument Default Description aPhaser.Point The Point object to rotate.
xnumber The x coordinate of the anchor point
ynumber The y coordinate of the anchor point
anglenumber The angle in radians (unless asDegrees is true) to rotate the Point by.
asDegreesboolean <optional>
false Is the given angle in radians (false) or degrees (true)?
distancenumber <optional>
An optional distance constraint between the Point and the anchor.
- Source:
- src/geom/Point.js line 821
Returns:
The modified point object.
- Type
- Phaser.Point
-
<static> rperp(a [, out])
-
Return a perpendicular vector (-90 degrees rotation)
Parameters:
Name Type Argument Description aPhaser.Point The Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 702
Returns:
The new Point object.
- Type
- Phaser.Point
-
<static> subtract(a, b [, out])
-
Subtracts the coordinates of two points to create a new point.
Parameters:
Name Type Argument Description aPhaser.Point The first Point object.
bPhaser.Point The second Point object.
outPhaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
- Source:
- src/geom/Point.js line 545
Returns:
The new Point object.
- Type
- Phaser.Point
-
add(x, y)
-
Adds the given x and y values to this Point.
Parameters:
Name Type Description xnumber The value to add to Point.x.
ynumber The value to add to Point.y.
- Source:
- src/geom/Point.js line 122
Returns:
This Point object. Useful for chaining method calls.
- Type
- Phaser.Point
-
angle(a [, asDegrees])
-
Returns the angle between this Point object and another object with public x and y properties.
Parameters:
Name Type Argument Default Description aPhaser.Point | any The object to get the angle from this Point to.
asDegreesboolean <optional>
false Is the given angle in radians (false) or degrees (true)?
- Source:
- src/geom/Point.js line 297
Returns:
The angle between the two objects.
- Type
- number
-
ceil()
-
Math.ceil() both the x and y properties of this Point.
- Source:
- src/geom/Point.js line 497
Returns:
This Point object.
- Type
- Phaser.Point
-
clamp(min, max)
-
Clamps this Point object values to be between the given min and max.
Parameters:
Name Type Description minnumber The minimum value to clamp this Point to.
maxnumber The maximum value to clamp this Point to.
- Source:
- src/geom/Point.js line 216
Returns:
This Point object.
- Type
- Phaser.Point
-
clampX(min, max)
-
Clamps the x value of this Point to be between the given min and max.
Parameters:
Name Type Description minnumber The minimum value to clamp this Point to.
maxnumber The maximum value to clamp this Point to.
- Source:
- src/geom/Point.js line 186
Returns:
This Point object.
- Type
- Phaser.Point
-
clampY(min, max)
-
Clamps the y value of this Point to be between the given min and max
Parameters:
Name Type Description minnumber The minimum value to clamp this Point to.
maxnumber The maximum value to clamp this Point to.
- Source:
- src/geom/Point.js line 201
Returns:
This Point object.
- Type
- Phaser.Point
-
clone( [output])
-
Creates a copy of the given Point.
Parameters:
Name Type Argument Description outputPhaser.Point <optional>
Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
- Source:
- src/geom/Point.js line 232
Returns:
The new Point object.
- Type
- Phaser.Point
-
copyFrom(source)
-
Copies the x and y properties from any given object to this Point.
Parameters:
Name Type Description sourceany The object to copy from.
- Source:
- src/geom/Point.js line 43
Returns:
This Point object.
- Type
- Phaser.Point
-
copyTo(dest)
-
Copies the x and y properties from this Point to any given object.
Parameters:
Name Type Description destany The object to copy to.
- Source:
- src/geom/Point.js line 254
Returns:
The dest object.
- Type
- object
-
cross(a)
-
The cross product of this and another Point object.
Parameters:
Name Type Description aPhaser.Point The Point object to get the cross product combined with this Point.
- Source:
- src/geom/Point.js line 436
Returns:
The result.
- Type
- number
-
distance(dest [, round])
-
Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties)
Parameters:
Name Type Argument Description destobject The target object. Must have visible x and y properties that represent the center of the object.
roundboolean <optional>
Round the distance to the nearest integer (default false).
- Source:
- src/geom/Point.js line 270
Returns:
The distance between this Point object and the destination Point object.
- Type
- number
-
divide(x, y)
-
Divides Point.x and Point.y by the given x and y values.
Parameters:
Name Type Description xnumber The value to divide Point.x by.
ynumber The value to divide Point.x by.
- Source:
- src/geom/Point.js line 170
Returns:
This Point object. Useful for chaining method calls.
- Type
- Phaser.Point
-
dot(a)
-
The dot product of this and another Point object.
Parameters:
Name Type Description aPhaser.Point The Point object to get the dot product combined with this Point.
- Source:
- src/geom/Point.js line 423
Returns:
The result.
- Type
- number
-
equals(a)
-
Determines whether the given objects x/y values are equal to this Point object.
Parameters:
Name Type Description aPhaser.Point | any The object to compare with this Point.
- Source:
- src/geom/Point.js line 284
Returns:
A value of true if the x and y points are equal, otherwise false.
- Type
- boolean
-
floor()
-
Math.floor() both the x and y properties of this Point.
- Source:
- src/geom/Point.js line 485
Returns:
This Point object.
- Type
- Phaser.Point
-
getMagnitude()
-
Calculates the length of the Point object.
- Source:
- src/geom/Point.js line 337
Returns:
The length of the Point.
- Type
- number
-
getMagnitudeSq()
-
Calculates the length squared of the Point object.
- Source:
- src/geom/Point.js line 349
Returns:
The length ^ 2 of the Point.
- Type
- number
-
invert()
-
Inverts the x and y values of this Point
- Source:
- src/geom/Point.js line 56
Returns:
This Point object.
- Type
- Phaser.Point
-
isZero()
-
Determine if this point is at 0,0.
- Source:
- src/geom/Point.js line 411
Returns:
True if this Point is 0,0, otherwise false.
- Type
- boolean
-
limit(max)
-
Alters the Point object so it's magnitude is at most the max value.
Parameters:
Name Type Description maxnumber The maximum magnitude for the Point.
- Source:
- src/geom/Point.js line 393
Returns:
This Point object.
- Type
- Phaser.Point
-
multiply(x, y)
-
Multiplies Point.x and Point.y by the given x and y values. Sometimes known as
Scale.Parameters:
Name Type Description xnumber The value to multiply Point.x by.
ynumber The value to multiply Point.x by.
- Source:
- src/geom/Point.js line 154
Returns:
This Point object. Useful for chaining method calls.
- Type
- Phaser.Point
-
normalize()
-
Alters the Point object so that its length is 1, but it retains the same direction.
- Source:
- src/geom/Point.js line 374
Returns:
This Point object.
- Type
- Phaser.Point
-
normalRightHand()
-
Right-hand normalize (make unit length) this Point.
- Source:
- src/geom/Point.js line 473
Returns:
This Point object.
- Type
- Phaser.Point
-
perp()
-
Make this Point perpendicular (90 degrees rotation)
- Source:
- src/geom/Point.js line 449
Returns:
This Point object.
- Type
- Phaser.Point
-
rotate(x, y, angle [, asDegrees] [, distance])
-
Rotates this Point around the x/y coordinates given to the desired angle.
Parameters:
Name Type Argument Default Description xnumber The x coordinate of the anchor point.
ynumber The y coordinate of the anchor point.
anglenumber The angle in radians (unless asDegrees is true) to rotate the Point to.
asDegreesboolean <optional>
false Is the given angle in radians (false) or degrees (true)?
distancenumber <optional>
An optional distance constraint between the Point and the anchor.
- Source:
- src/geom/Point.js line 320
Returns:
The modified point object.
- Type
- Phaser.Point
-
rperp()
-
Make this Point perpendicular (-90 degrees rotation)
- Source:
- src/geom/Point.js line 461
Returns:
This Point object.
- Type
- Phaser.Point
-
set(x [, y])
-
Sets the
xandyvalues of this Point object to the given values. If you omit theyvalue then thexvalue will be applied to both, for example:Point.set(2)is the same asPoint.set(2, 2)Identical to setTo.
Parameters:
Name Type Argument Description xnumber The horizontal value of this point.
ynumber <optional>
The vertical value of this point. If not given the x value will be used in its place.
- Source:
- src/geom/Point.js line 86
Returns:
This Point object. Useful for chaining method calls.
- Type
- Phaser.Point
-
set(obj, x [, y])
-
Sets the
xandyvalues of an object and returns the object.Parameters:
Name Type Argument Description objobject An object with numeric x and y properties.
xnumber The x value.
ynumber <optional>
The y value. If not given the x value will be used in its place.
- Source:
- src/geom/Point.js line 952
Returns:
The object. Useful for chaining method calls.
- Type
- object
-
setMagnitude(magnitude)
-
Alters the length of the Point without changing the direction.
Parameters:
Name Type Description magnitudenumber The desired magnitude of the resulting Point.
- Source:
- src/geom/Point.js line 361
Returns:
This Point object.
- Type
- Phaser.Point
-
setTo(x [, y])
-
Sets the
xandyvalues of this Point object to the given values. If you omit theyvalue then thexvalue will be applied to both, for example:Point.setTo(2)is the same asPoint.setTo(2, 2)Identical to set.
Parameters:
Name Type Argument Description xnumber The horizontal value of this point.
ynumber <optional>
The vertical value of this point. If not given the x value will be used in its place.
- Source:
- src/geom/Point.js line 68
Returns:
This Point object. Useful for chaining method calls.
- Type
- Phaser.Point
-
setToPolar(azimuth [, radius] [, asDegrees])
-
Sets the
xandyvalues of this Point object from a given polar coordinate.Parameters:
Name Type Argument Default Description azimuthnumber The angular coordinate, in radians (unless
asDegrees).radiusnumber <optional>
1 The radial coordinate (length).
asDegreesboolean <optional>
false True if
azimuthis in degrees.- Source:
- src/geom/Point.js line 104
Returns:
This Point object. Useful for chaining method calls.
- Type
- Phaser.Point
-
subtract(x, y)
-
Subtracts the given x and y values from this Point.
Parameters:
Name Type Description xnumber The value to subtract from Point.x.
ynumber The value to subtract from Point.y.
- Source:
- src/geom/Point.js line 138
Returns:
This Point object. Useful for chaining method calls.
- Type
- Phaser.Point
-
toString()
-
Returns a string representation of this object.
- Source:
- src/geom/Point.js line 509
Returns:
A string representation of the instance.
- Type
- string