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 - geom/Point.js, line 18
Members
-
x :number
-
The x value of the point.
- Source - geom/Point.js, line 26
-
y :number
-
The y value of the point.
- Source - geom/Point.js, line 31
Methods
-
<static> add(a, b, out) → {Phaser.Point}
-
Adds the coordinates of two points together to create a new point.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 498
-
<static> angle(a, b) → {number}
-
Returns the angle between two Point objects.
Parameters:
Name Type Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
Returns:
number -The angle between the two Points.
- Source - geom/Point.js, line 592
-
<static> angleSq(a, b) → {number}
-
Returns the angle squared between two Point objects.
Parameters:
Name Type Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
Returns:
number -The angle squared between the two Points.
- Source - geom/Point.js, line 607
-
<static> centroid(points, out) → {Phaser.Point}
-
Calculates centroid (or midpoint) from an array of points. If only one point is provided, that point is returned.
Parameters:
Name Type Argument Description points
Phaser.Point[] The array of one or more points.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 842
-
<static> distance(a, b, round) → {number}
-
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 Default Description a
object The target object. Must have visible x and y properties that represent the center of the object.
b
object The target object. Must have visible x and y properties that represent the center of the object.
round
boolean <optional>
false Round the distance to the nearest integer.
Returns:
number -The distance between this Point object and the destination Point object.
- Source - geom/Point.js, line 705
-
<static> divide(a, b, out) → {Phaser.Point}
-
Divides the coordinates of two points to create a new point.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 558
-
<static> equals(a, b) → {boolean}
-
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 a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
Returns:
boolean -A value of true if the Points are equal, otherwise false.
- Source - geom/Point.js, line 578
-
<static> interpolate(a, b, f, out) → {Phaser.Point}
-
Interpolates the two given Points, based on the
f
value (between 0 and 1) and returns a new Point.Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
f
number 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.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 655
-
<static> multiply(a, b, out) → {Phaser.Point}
-
Multiplies the coordinates of two points to create a new point.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 538
-
<static> multiplyAdd(a, b, s, out) → {Phaser.Point}
-
Adds two 2D Points together and multiplies the result by the given scalar.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
s
number The scaling value.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 637
-
<static> negative(a, out) → {Phaser.Point}
-
Creates a negative Point.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 621
-
<static> normalize(a, out) → {Phaser.Point}
-
Normalize (make unit length) a Point.
Parameters:
Name Type Argument Description a
Phaser.Point The Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 785
-
<static> normalRightHand(a, out) → {Phaser.Point}
-
Right-hand normalize (make unit length) a Point.
Parameters:
Name Type Argument Description a
Phaser.Point The Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 769
-
<static> parse(obj, xProp, yProp) → {Phaser.Point}
-
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 obj
Object The object to parse.
xProp
string <optional>
'x' The property used to set the Point.x value.
yProp
string <optional>
'y' The property used to set the Point.y value.
Returns:
The new Point object.
- Source - geom/Point.js, line 883
-
<static> perp(a, out) → {Phaser.Point}
-
Return a perpendicular vector (90 degrees rotation)
Parameters:
Name Type Argument Description a
Phaser.Point The Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 673
-
<static> project(a, b, out) → {Phaser.Point}
-
Project two Points onto another Point.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 721
-
<static> projectUnit(a, b, out) → {Phaser.Point}
-
Project two Points onto a Point of unit length.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 745
-
<static> rotate(a, x, y, angle, asDegrees, distance) → {Phaser.Point}
-
Rotates a Point around the x/y coordinates given to the desired angle.
Parameters:
Name Type Argument Default Description a
Phaser.Point The Point object to rotate.
x
number The x coordinate of the anchor point
y
number The y coordinate of the anchor point
angle
number The angle in radians (unless asDegrees is true) to rotate the Point to.
asDegrees
boolean <optional>
false Is the given rotation in radians (false) or degrees (true)?
distance
number <optional>
An optional distance constraint between the Point and the anchor.
Returns:
The modified point object.
- Source - geom/Point.js, line 808
-
<static> rperp(a, out) → {Phaser.Point}
-
Return a perpendicular vector (-90 degrees rotation)
Parameters:
Name Type Argument Description a
Phaser.Point The Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 689
-
<static> subtract(a, b, out) → {Phaser.Point}
-
Subtracts the coordinates of two points to create a new point.
Parameters:
Name Type Argument Description a
Phaser.Point The first Point object.
b
Phaser.Point The second Point object.
out
Phaser.Point <optional>
Optional Point to store the value in, if not supplied a new Point object will be created.
Returns:
The new Point object.
- Source - geom/Point.js, line 518
-
add(x, y) → {Phaser.Point}
-
Adds the given x and y values to this Point.
Parameters:
Name Type Description x
number The value to add to Point.x.
y
number The value to add to Point.y.
Returns:
This Point object. Useful for chaining method calls.
- Source - geom/Point.js, line 100
-
angle(a, asDegrees) → {number}
-
Returns the angle between this Point object and another object with public x and y properties.
Parameters:
Name Type Argument Default Description a
Phaser.Point | any The object to get the angle from this Point to.
asDegrees
boolean <optional>
false Is the given angle in radians (false) or degrees (true)?
Returns:
number -The angle between the two objects.
- Source - geom/Point.js, line 275
-
angleSq(a) → {number}
-
Returns the angle squared between this Point object and another object with public x and y properties.
Parameters:
Name Type Description a
Phaser.Point | any The object to get the angleSq from this Point to.
Returns:
number -The angleSq between the two objects.
- Source - geom/Point.js, line 298
-
ceil() → {Phaser.Point}
-
Math.ceil() both the x and y properties of this Point.
Returns:
This Point object.
- Source - geom/Point.js, line 470
-
clamp(min, max) → {Phaser.Point}
-
Clamps this Point object values to be between the given min and max.
Parameters:
Name Type Description min
number The minimum value to clamp this Point to.
max
number The maximum value to clamp this Point to.
Returns:
This Point object.
- Source - geom/Point.js, line 194
-
clampX(min, max) → {Phaser.Point}
-
Clamps the x value of this Point to be between the given min and max.
Parameters:
Name Type Description min
number The minimum value to clamp this Point to.
max
number The maximum value to clamp this Point to.
Returns:
This Point object.
- Source - geom/Point.js, line 164
-
clampY(min, max) → {Phaser.Point}
-
Clamps the y value of this Point to be between the given min and max
Parameters:
Name Type Description min
number The minimum value to clamp this Point to.
max
number The maximum value to clamp this Point to.
Returns:
This Point object.
- Source - geom/Point.js, line 179
-
clone(output) → {Phaser.Point}
-
Creates a copy of the given Point.
Parameters:
Name Type Argument Description output
Phaser.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.
Returns:
The new Point object.
- Source - geom/Point.js, line 210
-
copyFrom(source) → {Phaser.Point}
-
Copies the x and y properties from any given object to this Point.
Parameters:
Name Type Description source
any The object to copy from.
Returns:
This Point object.
- Source - geom/Point.js, line 37
-
copyTo(dest) → {Object}
-
Copies the x and y properties from this Point to any given object.
Parameters:
Name Type Description dest
any The object to copy to.
Returns:
Object -The dest object.
- Source - geom/Point.js, line 232
-
cross(a) → {number}
-
The cross product of this and another Point object.
Parameters:
Name Type Description a
Phaser.Point The Point object to get the cross product combined with this Point.
Returns:
number -The result.
- Source - geom/Point.js, line 409
-
distance(dest, round) → {number}
-
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 dest
object The target object. Must have visible x and y properties that represent the center of the object.
round
boolean <optional>
Round the distance to the nearest integer (default false).
Returns:
number -The distance between this Point object and the destination Point object.
- Source - geom/Point.js, line 248
-
divide(x, y) → {Phaser.Point}
-
Divides Point.x and Point.y by the given x and y values.
Parameters:
Name Type Description x
number The value to divide Point.x by.
y
number The value to divide Point.x by.
Returns:
This Point object. Useful for chaining method calls.
- Source - geom/Point.js, line 148
-
dot(a) → {number}
-
The dot product of this and another Point object.
Parameters:
Name Type Description a
Phaser.Point The Point object to get the dot product combined with this Point.
Returns:
number -The result.
- Source - geom/Point.js, line 396
-
equals(a) → {boolean}
-
Determines whether the given objects x/y values are equal to this Point object.
Parameters:
Name Type Description a
Phaser.Point | any The object to compare with this Point.
Returns:
boolean -A value of true if the x and y points are equal, otherwise false.
- Source - geom/Point.js, line 262
-
floor() → {Phaser.Point}
-
Math.floor() both the x and y properties of this Point.
Returns:
This Point object.
- Source - geom/Point.js, line 458
-
getMagnitude() → {number}
-
Calculates the length of the Point object.
Returns:
number -The length of the Point.
- Source - geom/Point.js, line 328
-
getMagnitudeSq() → {number}
-
Calculates the length squared of the Point object.
Returns:
number -The length ^ 2 of the Point.
- Source - geom/Point.js, line 340
-
invert() → {Phaser.Point}
-
Inverts the x and y values of this Point
Returns:
This Point object.
- Source - geom/Point.js, line 50
-
isZero() → {boolean}
-
Determine if this point is at 0,0.
Returns:
boolean -True if this Point is 0,0, otherwise false.
- Source - geom/Point.js, line 384
-
multiply(x, y) → {Phaser.Point}
-
Multiplies Point.x and Point.y by the given x and y values. Sometimes known as
Scale
.Parameters:
Name Type Description x
number The value to multiply Point.x by.
y
number The value to multiply Point.x by.
Returns:
This Point object. Useful for chaining method calls.
- Source - geom/Point.js, line 132
-
normalize() → {Phaser.Point}
-
Alters the Point object so that its length is 1, but it retains the same direction.
Returns:
This Point object.
- Source - geom/Point.js, line 365
-
normalRightHand() → {Phaser.Point}
-
Right-hand normalize (make unit length) this Point.
Returns:
This Point object.
- Source - geom/Point.js, line 446
-
perp() → {Phaser.Point}
-
Make this Point perpendicular (90 degrees rotation)
Returns:
This Point object.
- Source - geom/Point.js, line 422
-
rotate(x, y, angle, asDegrees, distance) → {Phaser.Point}
-
Rotates this Point around the x/y coordinates given to the desired angle.
Parameters:
Name Type Argument Description x
number The x coordinate of the anchor point.
y
number The y coordinate of the anchor point.
angle
number The angle in radians (unless asDegrees is true) to rotate the Point to.
asDegrees
boolean Is the given rotation in radians (false) or degrees (true)?
distance
number <optional>
An optional distance constraint between the Point and the anchor.
Returns:
The modified point object.
- Source - geom/Point.js, line 311
-
rperp() → {Phaser.Point}
-
Make this Point perpendicular (-90 degrees rotation)
Returns:
This Point object.
- Source - geom/Point.js, line 434
-
set(x, y) → {Phaser.Point}
-
Sets the
x
andy
values of this Point object to the given values. If you omit they
value then thex
value will be applied to both, for example:Point.setTo(2)
is the same asPoint.setTo(2, 2)
Parameters:
Name Type Argument Description x
number The horizontal value of this point.
y
number <optional>
The vertical value of this point. If not given the x value will be used in its place.
Returns:
This Point object. Useful for chaining method calls.
- Source - geom/Point.js, line 81
-
setMagnitude(magnitude) → {Phaser.Point}
-
Alters the length of the Point without changing the direction.
Parameters:
Name Type Description magnitude
number The desired magnitude of the resulting Point.
Returns:
This Point object.
- Source - geom/Point.js, line 352
-
setTo(x, y) → {Phaser.Point}
-
Sets the
x
andy
values of this Point object to the given values. If you omit they
value then thex
value will be applied to both, for example:Point.setTo(2)
is the same asPoint.setTo(2, 2)
Parameters:
Name Type Argument Description x
number The horizontal value of this point.
y
number <optional>
The vertical value of this point. If not given the x value will be used in its place.
Returns:
This Point object. Useful for chaining method calls.
- Source - geom/Point.js, line 62
-
subtract(x, y) → {Phaser.Point}
-
Subtracts the given x and y values from this Point.
Parameters:
Name Type Description x
number The value to subtract from Point.x.
y
number The value to subtract from Point.y.
Returns:
This Point object. Useful for chaining method calls.
- Source - geom/Point.js, line 116
-
toString() → {string}
-
Returns a string representation of this object.
Returns:
string -A string representation of the instance.
- Source - geom/Point.js, line 482