Namespace: Transform

Phaser.GameObjects.Components. Transform

Provides methods used for getting and setting the position, scale and rotation of a Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 15)

Members


angle :integer

The angle of this Game Object as expressed in degrees.

Where 0 is to the right, 90 is down, 180 is left.

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

Type:
  • integer
Since: 3.0.0
Default Value:
  • 0
Source: src/gameobjects/components/Transform.js (Line 196)

rotation :number

The angle of this Game Object in radians.

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

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/gameobjects/components/Transform.js (Line 222)

scale :number

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
Since: 3.18.0
Default Value:
  • 1
Source: src/gameobjects/components/Transform.js (Line 98)

scaleX :number

The horizontal scale of this Game Object.

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/gameobjects/components/Transform.js (Line 134)

scaleY :number

The vertical scale of this Game Object.

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/gameobjects/components/Transform.js (Line 165)

w :number

The w position of this Game Object.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/gameobjects/components/Transform.js (Line 88)

x :number

The x position of this Game Object.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/gameobjects/components/Transform.js (Line 57)

y :number

The y position of this Game Object.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/gameobjects/components/Transform.js (Line 67)

z :number

The z position of this Game Object. Note: Do not use this value to set the z-index, instead see the depth property.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/gameobjects/components/Transform.js (Line 77)

Methods


getLocalTransformMatrix( [tempMatrix])

Gets the local transform matrix for this Game Object.

Parameters:
Name Type Argument Description
tempMatrix Phaser.GameObjects.Components.TransformMatrix <optional>

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

Since: 3.4.0
Source: src/gameobjects/components/Transform.js (Line 442)
Returns:

The populated Transform Matrix.

Type
Phaser.GameObjects.Components.TransformMatrix

getParentRotation()

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.

Since: 3.18.0
Source: src/gameobjects/components/Transform.js (Line 496)
Returns:

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

Type
number

getWorldTransformMatrix( [tempMatrix] [, parentMatrix])

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

Parameters:
Name Type Argument 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.

Since: 3.4.0
Source: src/gameobjects/components/Transform.js (Line 459)
Returns:

The populated Transform Matrix.

Type
Phaser.GameObjects.Components.TransformMatrix

setAngle( [degrees])

Sets the angle of this Game Object.

Parameters:
Name Type Argument Default Description
degrees number <optional>
0

The rotation of this Game Object, in degrees.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 325)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

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

Sets the position of this Game Object.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 246)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

setRandomPosition( [x] [, y] [, width] [, height])

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 Argument Default Description
x number <optional>
0

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

y number <optional>
0

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.

Since: 3.8.0
Source: src/gameobjects/components/Transform.js (Line 274)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

setRotation( [radians])

Sets the rotation of this Game Object.

Parameters:
Name Type Argument Default Description
radians number <optional>
0

The rotation of this Game Object, in radians.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 306)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

setScale(x [, y])

Sets the scale of this Game Object.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 344)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

setW( [value])

Sets the w position of this Game Object.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The w position of this Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 423)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

setX( [value])

Sets the x position of this Game Object.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The x position of this Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 366)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

setY( [value])

Sets the y position of this Game Object.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The y position of this Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 385)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform

setZ( [value])

Sets the z position of this Game Object.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The z position of this Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Transform.js (Line 404)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Transform