Phaser API Documentation

  Version: 
Filter

A representation of a vector in 4D space.

A four-component vector.

Constructor:

new Vector4([x], [y], [z], [w])

Parameters:

name type arguments description
x number <optional>

The x component.

y number <optional>

The y component.

z number <optional>

The z component.

w number <optional>

The w component.

Since: 3.0.0
Source: src/math/Vector4.js (Line 12)

Members

w: number
Focus
Focus

Description:

The w component of this Vector.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Vector4.js (Line 64)
Focus
Focus
x: number
Focus
Focus

Description:

The x component of this Vector.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Vector4.js (Line 34)
Focus
Focus
y: number
Focus
Focus

Description:

The y component of this Vector.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Vector4.js (Line 44)
Focus
Focus
z: number
Focus
Focus

Description:

The z component of this Vector.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Vector4.js (Line 54)
Focus
Focus

Methods

add(v)
Focus
Focus

Description:

Add a given Vector to this Vector. Addition is component-wise.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4

The Vector to add to this Vector.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 173)
Focus
Focus
clone()
Focus
Focus

Description:

Make a clone of this Vector4.

Returns:
Description:

A clone of this Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 90)
Focus
Focus
copy(src)
Focus
Focus

Description:

Copy the components of a given Vector into this Vector.

Parameters:

name type description
src Phaser.Math.Vector4

The Vector to copy the components from.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 103)
Focus
Focus
distance(v)
Focus
Focus

Description:

Calculate the distance between this Vector and the given Vector.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4

The Vector to calculate the distance to.

Returns:
Description:

The distance from this Vector to the given Vector.

Type:
  • number
Since: 3.0.0
Source: src/math/Vector4.js (Line 389)
Focus
Focus
distanceSq(v)
Focus
Focus

Description:

Calculate the distance between this Vector and the given Vector, squared.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4

The Vector to calculate the distance to.

Returns:
Description:

The distance from this Vector to the given Vector, squared.

Type:
  • number
Since: 3.0.0
Source: src/math/Vector4.js (Line 409)
Focus
Focus
divide(v)
Focus
Focus

Description:

Perform a component-wise division between this Vector and the given Vector.

Divides this Vector by the given Vector.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4

The Vector to divide this Vector by.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 367)
Focus
Focus
dot(v)
Focus
Focus

Description:

Calculate the dot product of this Vector and the given Vector.

Parameters:

name type description
v Phaser.Math.Vector4

The Vector4 to dot product with this Vector4.

Returns:
Description:

The dot product of this Vector and the given Vector.

Type:
  • number
Since: 3.0.0
Source: src/math/Vector4.js (Line 300)
Focus
Focus
equals(v)
Focus
Focus

Description:

Check whether this Vector is equal to a given Vector.

Performs a strict quality check against each Vector's components.

Parameters:

name type description
v Phaser.Math.Vector4

The vector to check equality with.

Returns:
Description:

A boolean indicating whether the two Vectors are equal or not.

Type:
  • boolean
Since: 3.0.0
Source: src/math/Vector4.js (Line 123)
Focus
Focus
length()
Focus
Focus

Description:

Calculate the length (or magnitude) of this Vector.

Returns:
Description:

The length of this Vector.

Type:
  • number
Since: 3.0.0
Source: src/math/Vector4.js (Line 233)
Focus
Focus
lengthSq()
Focus
Focus

Description:

Calculate the length of this Vector squared.

Returns:
Description:

The length of this Vector, squared.

Type:
  • number
Since: 3.0.0
Source: src/math/Vector4.js (Line 251)
Focus
Focus
lerp(v, [t])
Focus
Focus

Description:

Linearly interpolate between this Vector and the given Vector.

Interpolates this Vector towards the given Vector.

Parameters:

name type arguments description
v Phaser.Math.Vector4

The Vector4 to interpolate towards.

t number <optional>

The interpolation percentage, between 0 and 1.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 315)
Focus
Focus
multiply(v)
Focus
Focus

Description:

Perform a component-wise multiplication between this Vector and the given Vector.

Multiplies this Vector by the given Vector.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4

The Vector to multiply this Vector by.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 345)
Focus
Focus
negate()
Focus
Focus

Description:

Negate the x, y, z and w components of this Vector.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 429)
Focus
Focus
normalize()
Focus
Focus

Description:

Normalize this Vector.

Makes the vector a unit length vector (magnitude of 1) in the same direction.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 269)
Focus
Focus
reset()
Focus
Focus

Description:

Make this Vector the zero vector (0, 0, 0, 0).

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 507)
Focus
Focus
scale(scale)
Focus
Focus

Description:

Scale this Vector by the given value.

Parameters:

name type description
scale number

The value to scale this Vector by.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 213)
Focus
Focus
set(x, y, z, w)
Focus
Focus

Description:

Set the x, y, z and w components of the this Vector to the given x, y, z and w values.

Parameters:

name type description
x number | object

The x value to set for this Vector, or an object containing x, y, z and w components.

y number

The y value to set for this Vector.

z number

The z value to set for this Vector.

w number

The z value to set for this Vector.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 140)
Focus
Focus
subtract(v)
Focus
Focus

Description:

Subtract the given Vector from this Vector. Subtraction is component-wise.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4

The Vector to subtract from this Vector.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 193)
Focus
Focus
transformMat4(mat)
Focus
Focus

Description:

Transform this Vector with the given Matrix.

Parameters:

name type description
mat Phaser.Math.Matrix4

The Matrix4 to transform this Vector4 with.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 447)
Focus
Focus
transformQuat(q)
Focus
Focus

Description:

Transform this Vector with the given Quaternion.

Parameters:

name type description
q Phaser.Math.Quaternion

The Quaternion to transform this Vector with.

Returns:
Description:

This Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 473)
Focus
Focus