Phaser API Documentation

  Version: 
Filter
Namespace: Transform
Phaser.GameObjects.Components.Transform

Members

<private> _rotation: number
Focus
Focus

Description:

Private internal value. Holds the rotation value in radians.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<private> _scaleX: number
Focus
Focus

Description:

Private internal value. Holds the horizontal scale value.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
<private> _scaleY: number
Focus
Focus

Description:

Private internal value. Holds the vertical scale value.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
angle: number
Focus
Focus

Description:

The angle of this Game Object as expressed in degrees.

Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left and -90 is up.

If you prefer to work in radians, see the rotation property instead.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
rotation: number
Focus
Focus

Description:

The angle of this Game Object in radians.

Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left and -PI/2 is up.

If you prefer to work in degrees, see the angle property instead.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
scale: number
Focus
Focus

Description:

This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object to the same value, at the same time. When reading this value the result returned is (scaleX + scaleY) / 2.

Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this isn't the case, use the scaleX or scaleY properties instead.

Type:
number
Default: 1
Since: 3.18.0
Focus
Focus
scaleX: number
Focus
Focus

Description:

The horizontal scale of this Game Object.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
scaleY: number
Focus
Focus

Description:

The vertical scale of this Game Object.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
w: number
Focus
Focus

Description:

The w position of this Game Object.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
x: number
Focus
Focus

Description:

The x position of this Game Object.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
y: number
Focus
Focus

Description:

The y position of this Game Object.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
z: number
Focus
Focus

Description:

The z position of this Game Object.

Note: The z position does not control the rendering order of 2D Game Objects. Use Phaser.GameObjects.Components.Depth#depth instead.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus

Methods

setPosition([x], [y], [z], [w])
Focus
Focus

Description:

Sets the position of this Game Object.

Parameters:

name type arguments Default description
x number <optional> 0

The x position of this Game Object.

y number <optional> x

The y position of this Game Object. If not set it will use the x value.

z number <optional> 0

The z position of this Game Object.

w number <optional> 0

The w position of this Game Object.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
copyPosition(source)
Focus
Focus

Description:

Copies an object's coordinates to this Game Object's position.

Parameters:

name type description
source Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like

An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied.

Returns:
Description:

This Game Object instance.

Since: 3.50.0
Focus
Focus
setRandomPosition([x], [y], [width], [height])
Focus
Focus

Description:

Sets the position of this Game Object to be a random position within the confines of the given area.

If no area is specified a random position between 0 x 0 and the game width x height is used instead.

The position does not factor in the size of this Game Object, meaning that only the origin is guaranteed to be within the area.

Parameters:

name type arguments description
x number <optional>

The x position of the top-left of the random area.

y number <optional>

The y position of the top-left of the random area.

width number <optional>

The width of the random area.

height number <optional>

The height of the random area.

Returns:
Description:

This Game Object instance.

Since: 3.8.0
Focus
Focus
setRotation([radians])
Focus
Focus

Description:

Sets the rotation of this Game Object.

Parameters:

name type arguments description
radians number <optional>

The rotation of this Game Object, in radians.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
setAngle([degrees])
Focus
Focus

Description:

Sets the angle of this Game Object.

Parameters:

name type arguments description
degrees number <optional>

The rotation of this Game Object, in degrees.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
setScale(x, [y])
Focus
Focus

Description:

Sets the scale of this Game Object.

Parameters:

name type arguments Default description
x number

The horizontal scale of this Game Object.

y number <optional> x

The vertical scale of this Game Object. If not set it will use the x value.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
setX([value])
Focus
Focus

Description:

Sets the x position of this Game Object.

Parameters:

name type arguments description
value number <optional>

The x position of this Game Object.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
setY([value])
Focus
Focus

Description:

Sets the y position of this Game Object.

Parameters:

name type arguments description
value number <optional>

The y position of this Game Object.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
setZ([value])
Focus
Focus

Description:

Sets the z position of this Game Object.

Note: The z position does not control the rendering order of 2D Game Objects. Use Phaser.GameObjects.Components.Depth#setDepth instead.

Parameters:

name type arguments description
value number <optional>

The z position of this Game Object.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
setW([value])
Focus
Focus

Description:

Sets the w position of this Game Object.

Parameters:

name type arguments description
value number <optional>

The w position of this Game Object.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
getLocalTransformMatrix([tempMatrix])
Focus
Focus

Description:

Gets the local transform matrix for this Game Object.

Parameters:

name type arguments description
tempMatrix Phaser.GameObjects.Components.TransformMatrix <optional>

The matrix to populate with the values from this Game Object.

Returns:
Description:

The populated Transform Matrix.

Since: 3.4.0
Focus
Focus
getWorldTransformMatrix([tempMatrix], [parentMatrix])
Focus
Focus

Description:

Gets the world transform matrix for this Game Object, factoring in any parent Containers.

Parameters:

name type arguments description
tempMatrix Phaser.GameObjects.Components.TransformMatrix <optional>

The matrix to populate with the values from this Game Object.

parentMatrix Phaser.GameObjects.Components.TransformMatrix <optional>

A temporary matrix to hold parent values during the calculations.

Returns:
Description:

The populated Transform Matrix.

Since: 3.4.0
Focus
Focus
getLocalPoint(x, y, [point], [camera])
Focus
Focus

Description:

Takes the given x and y coordinates and converts them into local space for this Game Object, taking into account parent and local transforms, and the Display Origin.

The returned Vector2 contains the translated point in its properties.

A Camera needs to be provided in order to handle modified scroll factors. If no camera is specified, it will use the main camera from the Scene to which this Game Object belongs.

Parameters:

name type arguments description
x number

The x position to translate.

y number

The y position to translate.

point Phaser.Math.Vector2 <optional>

A Vector2, or point-like object, to store the results in.

camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera which is being tested against. If not given will use the Scene default camera.

Returns:
Description:

The translated point.

Since: 3.50.0
Focus
Focus
getParentRotation()
Focus
Focus

Description:

Gets the sum total rotation of all of this Game Objects parent Containers.

The returned value is in radians and will be zero if this Game Object has no parent container.

Returns:
Description:

The sum total rotation, in radians, of all parent containers of this Game Object.

Type:
  • number
Since: 3.18.0
Focus
Focus