Skip to main content
Version: Phaser v3.88.2

Rectangle

The Rectangle Shape is a Game Object that can be added to a Scene, Group or Container. You can

treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling

it for input or physics. It provides a quick and easy way for you to render this shape in your

game without using a texture, while still taking advantage of being fully batched in WebGL.

This shape supports both fill and stroke colors.

You can change the size of the rectangle by changing the width and height properties.

Constructor

new Rectangle(scene, x, y, [width], [height], [fillColor], [fillAlpha])

Parameters

nametypeoptionaldefaultdescription
scenePhaser.SceneNoThe Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
xnumberNoThe horizontal position of this Game Object in the world.
ynumberNoThe vertical position of this Game Object in the world.
widthnumberYes128The width of the rectangle.
heightnumberYes128The height of the rectangle.
fillColornumberYesThe color the rectangle will be filled with, i.e. 0xff0000 for red.
fillAlphanumberYesThe alpha the rectangle will be filled with. You can also set the alpha of the overall Shape using its alpha property.

Scope: static

Extends

Phaser.GameObjects.Shape

Source: src/gameobjects/shape/rectangle/Rectangle.js#L12
Since: 3.13.0

Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.GetBounds:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.Pipeline:

From Phaser.GameObjects.Components.PostPipeline:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shape:


Public Methods

setSize

<instance> setSize(width, height)

Description:

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

If you have assigned a custom input hit area for this Rectangle, changing the Rectangle size will not change the

size of the hit area. To do this you should adjust the input.hitArea object directly.

Parameters:

nametypeoptionaldescription
widthnumberNoThe width of this Game Object.
heightnumberNoThe height of this Game Object.

Overrides: Phaser.GameObjects.Shape#setSize

Returns: Phaser.GameObjects.Rectangle - This Game Object instance.

Source: src/gameobjects/shape/rectangle/Rectangle.js#L68
Since: 3.13.0


Inherited Members

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.Pipeline:

From Phaser.GameObjects.Components.PostPipeline:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shape: