Namespace: Size

Phaser.GameObjects.Components. Size

Provides methods used for getting and setting the size of a Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 7)

Members


displayHeight :number

The displayed height of this Game Object.

This value takes into account the scale factor.

Setting this value will adjust the Game Object's scale property.

Type:
  • number
Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 78)

displayWidth :number

The displayed width of this Game Object.

This value takes into account the scale factor.

Setting this value will adjust the Game Object's scale property.

Type:
  • number
Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 53)

height :number

The native (un-scaled) height of this Game Object.

Changing this value will not change the size that the Game Object is rendered in-game. For that you need to either set the scale of the Game Object (setScale) or use the displayHeight property.

Type:
  • number
Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 40)

width :number

The native (un-scaled) width of this Game Object.

Changing this value will not change the size that the Game Object is rendered in-game. For that you need to either set the scale of the Game Object (setScale) or use the displayWidth property.

Type:
  • number
Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 27)

Methods


setDisplaySize(width, height)

Sets the display size of this Game Object.

Calling this will adjust the scale.

Parameters:
Name Type Description
width number

The width of this Game Object.

height number

The height of this Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 158)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Size

setSize(width, height)

Sets the internal size of this Game Object, as used for frame or physics body creation.

This will not change the size that the Game Object is rendered in-game. For that you need to either set the scale of the Game Object (setScale) or call the setDisplaySize method, which is the same thing as changing the scale but allows you to do so by giving pixel values.

If you have enabled this Game Object for input, changing the size will not change the size of the hit area. To do this you should adjust the input.hitArea object directly.

Parameters:
Name Type Description
width number

The width of this Game Object.

height number

The height of this Game Object.

Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 131)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Size

setSizeToFrame(frame)

Sets the size of this Game Object to be that of the given Frame.

This will not change the size that the Game Object is rendered in-game. For that you need to either set the scale of the Game Object (setScale) or call the setDisplaySize method, which is the same thing as changing the scale but allows you to do so by giving pixel values.

If you have enabled this Game Object for input, changing the size will not change the size of the hit area. To do this you should adjust the input.hitArea object directly.

Parameters:
Name Type Description
frame Phaser.Textures.Frame

The frame to base the size of this Game Object on.

Since: 3.0.0
Source: src/gameobjects/components/Size.js (Line 103)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Components.Size