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.
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. |
The const type of this object.
The x value of the point.
The y value of the point.
Adds the coordinates of two points together to create a new point.
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. |
The new Point object.
Returns the angle between two Point objects.
Name | Type | Description |
---|---|---|
a | Phaser.Point | The first Point object. |
b | Phaser.Point | The second Point object. |
The angle between the two Points.
Calculates centroid (or midpoint) from an array of points. If only one point is provided, that point is returned.
Name | Type | Argument | Description |
---|---|---|---|
points | Array.<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. |
The new Point object.
Returns the euclidian distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties).
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. |
The distance between this Point object and the destination Point object.
Divides the coordinates of two points to create a new point.
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. |
The new Point object.
Determines whether the two given Point objects are equal. They are considered equal if they have the same x and y values.
Name | Type | Description |
---|---|---|
a | Phaser.Point | The first Point object. |
b | Phaser.Point | The second Point object. |
A value of true if the Points are equal, otherwise false.
Interpolates the two given Points, based on the f
value (between 0 and 1) and returns a new Point.
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. |
The new Point object.
Multiplies the coordinates of two points to create a new point.
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. |
The new Point object.
Adds two 2D Points together and multiplies the result by the given scalar.
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. |
The new Point object.
Creates a negative Point.
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. |
The new Point object.
Normalize (make unit length) a Point.
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. |
The new Point object.
Right-hand normalize (make unit length) a Point.
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. |
The new Point object.
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.
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. |
The new Point object.
Return a perpendicular vector (90 degrees rotation)
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. |
The new Point object.
Project two Points onto another Point.
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. |
The new Point object.
Project two Points onto a Point of unit length.
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. |
The new Point object.
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.
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 by. | ||
asDegrees | boolean | <optional> | false | Is the given angle in radians (false) or degrees (true)? |
distance | number | <optional> | An optional distance constraint between the Point and the anchor. |
The modified point object.
Return a perpendicular vector (-90 degrees rotation)
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. |
The new Point object.
Subtracts the coordinates of two points to create a new point.
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. |
The new Point object.
Adds the given x and y values to this Point.
Name | Type | Description |
---|---|---|
x | number | The value to add to Point.x. |
y | number | The value to add to Point.y. |
This Point object. Useful for chaining method calls.
Returns the angle between this Point object and another object with public x and y properties.
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)? |
The angle between the two objects.
Math.ceil() both the x and y properties of this Point.
This Point object.
Clamps this Point object values to be between the given min and max.
Name | Type | Description |
---|---|---|
min | number | The minimum value to clamp this Point to. |
max | number | The maximum value to clamp this Point to. |
This Point object.
Clamps the x value of this Point to be between the given min and max.
Name | Type | Description |
---|---|---|
min | number | The minimum value to clamp this Point to. |
max | number | The maximum value to clamp this Point to. |
This Point object.
Clamps the y value of this Point to be between the given min and max
Name | Type | Description |
---|---|---|
min | number | The minimum value to clamp this Point to. |
max | number | The maximum value to clamp this Point to. |
This Point object.
Creates a copy of the given Point.
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. |
The new Point object.
Copies the x and y properties from any given object to this Point.
Name | Type | Description |
---|---|---|
source | any | The object to copy from. |
This Point object.
Copies the x and y properties from this Point to any given object.
Name | Type | Description |
---|---|---|
dest | any | The object to copy to. |
The dest object.
The cross product of this and another Point object.
Name | Type | Description |
---|---|---|
a | Phaser.Point | The Point object to get the cross product combined with this Point. |
The result.
Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties)
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). |
The distance between this Point object and the destination Point object.
Divides Point.x and Point.y by the given x and y values.
Name | Type | Description |
---|---|---|
x | number | The value to divide Point.x by. |
y | number | The value to divide Point.x by. |
This Point object. Useful for chaining method calls.
The dot product of this and another Point object.
Name | Type | Description |
---|---|---|
a | Phaser.Point | The Point object to get the dot product combined with this Point. |
The result.
Determines whether the given objects x/y values are equal to this Point object.
Name | Type | Description |
---|---|---|
a | Phaser.Point | any | The object to compare with this Point. |
A value of true if the x and y points are equal, otherwise false.
Math.floor() both the x and y properties of this Point.
This Point object.
Calculates the length of the Point object.
The length of the Point.
Calculates the length squared of the Point object.
The length ^ 2 of the Point.
Inverts the x and y values of this Point
This Point object.
Determine if this point is at 0,0.
True if this Point is 0,0, otherwise false.
Multiplies Point.x and Point.y by the given x and y values. Sometimes known as Scale
.
Name | Type | Description |
---|---|---|
x | number | The value to multiply Point.x by. |
y | number | The value to multiply Point.x by. |
This Point object. Useful for chaining method calls.
Alters the Point object so that its length is 1, but it retains the same direction.
This Point object.
Right-hand normalize (make unit length) this Point.
This Point object.
Make this Point perpendicular (90 degrees rotation)
This Point object.
Rotates this Point around the x/y coordinates given to the desired angle.
Name | Type | Argument | Default | 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 | <optional> | false | Is the given angle in radians (false) or degrees (true)? |
distance | number | <optional> | An optional distance constraint between the Point and the anchor. |
The modified point object.
Make this Point perpendicular (-90 degrees rotation)
This Point object.
Sets the x
and y
values of this Point object to the given values.
If you omit the y
value then the x
value will be applied to both, for example:Point.set(2)
is the same as Point.set(2, 2)
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. |
This Point object. Useful for chaining method calls.
Alters the length of the Point without changing the direction.
Name | Type | Description |
---|---|---|
magnitude | number | The desired magnitude of the resulting Point. |
This Point object.
Sets the x
and y
values of this Point object to the given values.
If you omit the y
value then the x
value will be applied to both, for example:Point.setTo(2)
is the same as Point.setTo(2, 2)
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. |
This Point object. Useful for chaining method calls.
Subtracts the given x and y values from this Point.
Name | Type | Description |
---|---|---|
x | number | The value to subtract from Point.x. |
y | number | The value to subtract from Point.y. |
This Point object. Useful for chaining method calls.
Returns a string representation of this object.
A string representation of the instance.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Point.html