Skip to main content
Version: Phaser v4.0.0

Phaser.Display.Align.In

BottomCenter

<static> BottomCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its bottom edge matches the bottom edge of the alignIn Game Object, with its horizontal center aligned to the horizontal center of alignIn.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/BottomCenter.js#L12
Since: 3.0.0

BottomLeft

<static> BottomLeft(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is positioned in the bottom-left of the other.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/BottomLeft.js#L12
Since: 3.0.0

BottomRight

<static> BottomRight(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is positioned inside the bottom-right corner of the alignIn Game Object. The right edge of gameObject is matched to the right edge of alignIn, and the bottom edge of gameObject is matched to the bottom edge of alignIn.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/BottomRight.js#L12
Since: 3.0.0

Center

<static> Center(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is positioned in the center of the other.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/Center.js#L11
Since: 3.0.0

LeftCenter

<static> LeftCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its left edge is flush with the left edge of the alignIn Game Object, and its vertical center matches the vertical center of alignIn. This places the Game Object at the left-center interior position of the reference object. An optional offset can be applied to adjust the final position along either axis.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/LeftCenter.js#L12
Since: 3.0.0

QuickSet

<static> QuickSet(child, alignIn, position, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is positioned relative to another Game Object. The alignment used is based on the position argument, which is an ALIGN_CONST value, such as LEFT_CENTER or TOP_RIGHT.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
childPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
positionnumberNoThe position to align the Game Object with. This is an align constant, such as ALIGN_CONST.LEFT_CENTER.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/QuickSet.js#L25
Since: 3.0.0

RightCenter

<static> RightCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its right edge is flush with the right edge of the alignIn Game Object, and its vertical center is aligned with the vertical center of the alignIn Game Object.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/RightCenter.js#L12
Since: 3.0.0

TopCenter

<static> TopCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its top edge is flush with the top edge of the alignIn Game Object, centered horizontally.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/TopCenter.js#L12
Since: 3.0.0

TopLeft

<static> TopLeft(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes the given Game Object and aligns it so that it is positioned in the top-left of the alignIn Game Object.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/TopLeft.js#L12
Since: 3.0.0

TopRight

<static> TopRight(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is positioned in the top-right of the alignIn Game Object.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignInPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/in/TopRight.js#L12
Since: 3.0.0

Phaser.Display.Align.To

BottomCenter

<static> BottomCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its top edge is flush with the bottom of the alignTo Game Object, centered horizontally on it.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/BottomCenter.js#L12
Since: 3.0.0

BottomLeft

<static> BottomLeft(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is placed directly below the alignTo Game Object, with its left edge aligned to the left edge of alignTo.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/BottomLeft.js#L12
Since: 3.0.0

BottomRight

<static> BottomRight(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is placed directly below and flush with the right edge of the other Game Object. The right edge of gameObject is aligned to the right edge of alignTo, and the top edge of gameObject is placed at the bottom edge of alignTo.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/BottomRight.js#L12
Since: 3.0.0

LeftBottom

<static> LeftBottom(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its right edge touches the left edge of the alignTo Game Object, with its bottom edge aligned to the bottom edge of alignTo.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/LeftBottom.js#L12
Since: 3.0.0

LeftCenter

<static> LeftCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its right edge touches the left edge of the alignTo Game Object, with their vertical centers matched.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/LeftCenter.js#L12
Since: 3.0.0

LeftTop

<static> LeftTop(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its right edge touches the left edge of the alignTo Game Object, with its top edge aligned to the top of alignTo.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/LeftTop.js#L12
Since: 3.0.0

QuickSet

<static> QuickSet(child, alignTo, position, [offsetX], [offsetY])

Description:

Takes a Game Object and aligns it next to another, at the given position. The alignment used is based on the position argument, which is a Phaser.Display.Align property such as LEFT_CENTER or TOP_RIGHT.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
childPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
positionnumberNoThe position to align the Game Object with. This is an align constant, such as Phaser.Display.Align.LEFT_CENTER.
offsetXnumberYes0Optional horizontal offset from the position, in pixels.
offsetYnumberYes0Optional vertical offset from the position, in pixels.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/QuickSet.js#L24
Since: 3.22.0

RightBottom

<static> RightBottom(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is placed immediately to the right of the alignTo Game Object, with their bottom edges aligned.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/RightBottom.js#L12
Since: 3.0.0

RightCenter

<static> RightCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its left edge is flush with the right edge of the alignTo Game Object, with their vertical centers matching.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/RightCenter.js#L12
Since: 3.0.0

RightTop

<static> RightTop(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its left edge is flush with the right edge of the alignTo Game Object, with its top edge matching the top edge of alignTo.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/RightTop.js#L12
Since: 3.0.0

TopCenter

<static> TopCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is placed directly above the alignTo Game Object, centered horizontally on it. The bottom edge of gameObject is positioned flush with the top edge of alignTo, and their center X coordinates are matched.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/TopCenter.js#L12
Since: 3.0.0

TopLeft

<static> TopLeft(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that its bottom edge sits flush with the top edge of the alignTo Game Object, with their left edges aligned. The result is that gameObject appears directly above alignTo, anchored to its left side.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/TopLeft.js#L12
Since: 3.0.0

TopRight

<static> TopRight(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes a given Game Object and aligns it so that it is positioned directly above the alignTo Game Object, with their right edges aligned.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be positioned.
alignToPhaser.GameObjects.GameObjectNoThe Game Object to base the alignment position on.
offsetXnumberYes0Optional horizontal offset from the position.
offsetYnumberYes0Optional vertical offset from the position.

Returns: Phaser.GameObjects.GameObject - The Game Object that was aligned.

Source: src/display/align/to/TopRight.js#L12
Since: 3.0.0

Phaser.Display.Bounds

CenterOn

<static> CenterOn(gameObject, x, y)

Description:

Positions the Game Object so that it is centered on the given coordinates.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be re-positioned.
xnumberNoThe horizontal coordinate to position the Game Object on.
ynumberNoThe vertical coordinate to position the Game Object on.

Returns: Phaser.GameObjects.GameObject - The Game Object that was positioned.

Source: src/display/bounds/CenterOn.js#L10
Since: 3.0.0

GetBottom

<static> GetBottom(gameObject)

Description:

Returns the bottom coordinate from the bounds of the Game Object.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The bottom coordinate of the bounds of the Game Object.

Source: src/display/bounds/GetBottom.js#L7
Since: 3.0.0

GetBounds

<static> GetBounds(gameObject, [output])

Description:

Returns the unrotated bounds of the Game Object as a rectangle.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.
outputPhaser.Geom.Rectangle | objectYesAn object to store the values in. If not provided a new Rectangle will be created.

Returns: Phaser.Geom.Rectangle, object - - The bounds of the Game Object.

Source: src/display/bounds/GetBounds.js#L13
Since: 3.24.0

GetCenterX

<static> GetCenterX(gameObject)

Description:

Returns the center x coordinate from the bounds of the Game Object.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The center x coordinate of the bounds of the Game Object.

Source: src/display/bounds/GetCenterX.js#L7
Since: 3.0.0

GetCenterY

<static> GetCenterY(gameObject)

Description:

Returns the center y coordinate from the bounds of the Game Object.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The center y coordinate of the bounds of the Game Object.

Source: src/display/bounds/GetCenterY.js#L7
Since: 3.0.0

GetLeft

<static> GetLeft(gameObject)

Description:

Returns the left coordinate from the bounds of the Game Object.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The left coordinate of the bounds of the Game Object.

Source: src/display/bounds/GetLeft.js#L7
Since: 3.0.0

GetOffsetX

<static> GetOffsetX(gameObject)

Description:

Returns the amount the Game Object is visually offset from its x coordinate. This is the same as width * origin.x. This value will only be > 0 if origin.x is not equal to zero.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The horizontal offset of the Game Object.

Source: src/display/bounds/GetOffsetX.js#L7
Since: 3.0.0

GetOffsetY

<static> GetOffsetY(gameObject)

Description:

Returns the amount the Game Object is visually offset from its y coordinate. This is the same as height * origin.y. This value will only be > 0 if origin.y is not equal to zero.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The vertical offset of the Game Object.

Source: src/display/bounds/GetOffsetY.js#L7
Since: 3.0.0

GetRight

<static> GetRight(gameObject)

Description:

Returns the right coordinate from the bounds of the Game Object.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The right coordinate of the bounds of the Game Object.

Source: src/display/bounds/GetRight.js#L7
Since: 3.0.0

GetTop

<static> GetTop(gameObject)

Description:

Returns the top coordinate from the bounds of the Game Object.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to get the bounds value from.

Returns: number - The top coordinate of the bounds of the Game Object.

Source: src/display/bounds/GetTop.js#L7
Since: 3.0.0

SetBottom

<static> SetBottom(gameObject, value)

Description:

Positions the Game Object so that the bottom of its bounds aligns with the given coordinate.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be re-positioned.
valuenumberNoThe coordinate to position the Game Object bounds on.

Returns: Phaser.GameObjects.GameObject - The Game Object that was positioned.

Source: src/display/bounds/SetBottom.js#L7
Since: 3.0.0

SetCenterX

<static> SetCenterX(gameObject, x)

Description:

Positions the Game Object so that the horizontal center of its bounds aligns with the given coordinate.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be re-positioned.
xnumberNoThe coordinate to position the Game Object bounds on.

Returns: Phaser.GameObjects.GameObject - The Game Object that was positioned.

Source: src/display/bounds/SetCenterX.js#L7
Since: 3.0.0

SetCenterY

<static> SetCenterY(gameObject, y)

Description:

Positions the Game Object so that the vertical center of its bounds aligns with the given coordinate.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be re-positioned.
ynumberNoThe coordinate to position the Game Object bounds on.

Returns: Phaser.GameObjects.GameObject - The Game Object that was positioned.

Source: src/display/bounds/SetCenterY.js#L7
Since: 3.0.0

SetLeft

<static> SetLeft(gameObject, value)

Description:

Positions the Game Object so that the left of its bounds aligns with the given coordinate.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be re-positioned.
valuenumberNoThe coordinate to position the Game Object bounds on.

Returns: Phaser.GameObjects.GameObject - The Game Object that was positioned.

Source: src/display/bounds/SetLeft.js#L7
Since: 3.0.0

SetRight

<static> SetRight(gameObject, value)

Description:

Positions the Game Object so that the right of its bounds aligns with the given coordinate.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be re-positioned.
valuenumberNoThe coordinate to position the Game Object bounds on.

Returns: Phaser.GameObjects.GameObject - The Game Object that was positioned.

Source: src/display/bounds/SetRight.js#L7
Since: 3.0.0

SetTop

<static> SetTop(gameObject, value)

Description:

Positions the Game Object so that the top of its bounds aligns with the given coordinate.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will be re-positioned.
valuenumberNoThe coordinate to position the Game Object bounds on.

Returns: Phaser.GameObjects.GameObject - The Game Object that was positioned.

Source: src/display/bounds/SetTop.js#L7
Since: 3.0.0

Phaser.Display.Canvas.CanvasInterpolation

setCrisp

<static> setCrisp(canvas)

Description:

Sets the CSS image-rendering property on the given canvas to use nearest-neighbor (crisp) scaling. This disables anti-aliasing so that each pixel is rendered as a hard-edged block, which is ideal for pixel art games. Multiple vendor-prefixed values are applied in sequence to ensure cross-browser compatibility, including Firefox (-moz-crisp-edges), Opera (-o-crisp-edges), WebKit (-webkit-optimize-contrast), and Internet Explorer (msInterpolationMode: nearest-neighbor).

Parameters:

nametypeoptionaldescription
canvasHTMLCanvasElementNoThe canvas object to have the style set on.

Returns: HTMLCanvasElement - The canvas.

Source: src/display/canvas/CanvasInterpolation.js#L21
Since: 3.0.0

setBicubic

<static> setBicubic(canvas)

Description:

Sets the CSS image-rendering property on the given canvas to auto, restoring the default browser behavior. This allows the browser to apply smooth (typically bicubic) interpolation when scaling the canvas, which produces softer edges and is better suited to high-resolution textures or non-pixel-art content. Also sets the IE-specific msInterpolationMode to bicubic.

Parameters:

nametypeoptionaldescription
canvasHTMLCanvasElementNoThe canvas object to have the style set on.

Returns: HTMLCanvasElement - The canvas.

Source: src/display/canvas/CanvasInterpolation.js#L49
Since: 3.0.0

Phaser.Display.Canvas.CanvasPool

create

<static> create(parent, [width], [height], [canvasType], [selfParent])

Description:

Creates a new Canvas DOM element, or pulls one from the pool if free.

Parameters:

nametypeoptionaldefaultdescription
parent*NoThe parent of the Canvas object.
widthnumberYes1The width of the Canvas.
heightnumberYes1The height of the Canvas.
canvasTypenumberYes"Phaser.CANVAS"The type of the Canvas. Either Phaser.CANVAS or Phaser.WEBGL.
selfParentbooleanYesfalseUse the generated Canvas element as the parent?

Returns: HTMLCanvasElement - The canvas element that was created or pulled from the pool.

Source: src/display/canvas/CanvasPool.js#L29
Since: 3.0.0

create2D

<static> create2D(parent, [width], [height])

Description:

Creates a new 2D Canvas DOM element, or pulls one from the pool if free.

This is a convenience wrapper around create that forces canvasType to Phaser.CANVAS, ensuring the returned canvas is always intended for use with a 2D rendering context.

Parameters:

nametypeoptionaldefaultdescription
parent*NoThe parent of the Canvas object.
widthnumberYes1The width of the Canvas.
heightnumberYes1The height of the Canvas.

Returns: HTMLCanvasElement - The canvas element that was created or pulled from the pool.

Source: src/display/canvas/CanvasPool.js#L91
Since: 3.0.0

createWebGL

<static> createWebGL(parent, [width], [height])

Description:

Creates a new WebGL Canvas DOM element.

This is a convenience wrapper around create that forces canvasType to Phaser.WEBGL. WebGL canvases are never added to the pool, because once a WebGL context's options are set they cannot be changed, making pooling unsuitable for them.

Parameters:

nametypeoptionaldefaultdescription
parent*NoThe parent of the Canvas object.
widthnumberYes1The width of the Canvas.
heightnumberYes1The height of the Canvas.

Returns: HTMLCanvasElement - The created WebGL canvas.

Source: src/display/canvas/CanvasPool.js#L111
Since: 3.0.0

first

<static> first([canvasType])

Description:

Gets the first free canvas container from the pool.

Parameters:

nametypeoptionaldefaultdescription
canvasTypenumberYes"Phaser.CANVAS"The type of the Canvas. Either Phaser.CANVAS or Phaser.WEBGL.

Returns: HTMLCanvasElement - The first free canvas, or null if a WebGL canvas was requested or if the pool doesn't have free canvases.

Source: src/display/canvas/CanvasPool.js#L132
Since: 3.0.0

remove

<static> remove(parent)

Description:

Looks up a canvas based on its parent, and if found puts it back in the pool, freeing it up for re-use. The canvas has its width and height set to 1, and its parent attribute nulled.

Parameters:

nametypeoptionaldescription
parent*NoThe canvas or the parent of the canvas to free.

Source: src/display/canvas/CanvasPool.js#L164
Since: 3.0.0

total

<static> total()

Description:

Gets the total number of used canvas elements in the pool.

Returns: number - The number of used canvases.

Source: src/display/canvas/CanvasPool.js#L189
Since: 3.0.0

free

<static> free()

Description:

Gets the total number of free canvas elements in the pool.

Returns: number - The number of free canvases.

Source: src/display/canvas/CanvasPool.js#L212
Since: 3.0.0

disableSmoothing

<static> disableSmoothing()

Description:

Disable context smoothing on any new Canvas element created.

Source: src/display/canvas/CanvasPool.js#L225
Since: 3.0.0

enableSmoothing

<static> enableSmoothing()

Description:

Enable context smoothing on any new Canvas element created.

Source: src/display/canvas/CanvasPool.js#L236
Since: 3.0.0

Phaser.Display.Canvas.Smoothing

getPrefix

<static> getPrefix(context)

Description:

Gets the Smoothing Enabled vendor prefix being used on the given context, or null if not set.

Parameters:

nametypeoptionaldescription
contextCanvasRenderingContext2D | WebGLRenderingContextNoThe canvas context to check.

Returns: string - The name of the property on the context which controls image smoothing (either imageSmoothingEnabled or a vendor-prefixed version thereof), or null if not supported.

Source: src/display/canvas/Smoothing.js#L24
Since: 3.0.0

enable

<static> enable(context)

Description:

Enables the Image Smoothing property on the given context. By default browsers have image smoothing enabled, which isn't always what you visually want, especially when using pixel art in a game. Note that this sets the property on the context itself, so that any image drawn to the context will be affected. This sets the property across all current browsers but support is patchy on earlier browsers, especially on mobile.

Parameters:

nametypeoptionaldescription
contextCanvasRenderingContext2D | WebGLRenderingContextNoThe context on which to enable smoothing.

Returns: CanvasRenderingContext2D, WebGLRenderingContext - The provided context.

Source: src/display/canvas/Smoothing.js#L51
Since: 3.0.0

disable

<static> disable(context)

Description:

Disables the Image Smoothing property on the given context. By default browsers have image smoothing enabled, which isn't always what you visually want, especially when using pixel art in a game. Note that this sets the property on the context itself, so that any image drawn to the context will be affected. This sets the property across all current browsers but support is patchy on earlier browsers, especially on mobile.

Parameters:

nametypeoptionaldescription
contextCanvasRenderingContext2D | WebGLRenderingContextNoThe context on which to disable smoothing.

Returns: CanvasRenderingContext2D, WebGLRenderingContext - The provided context.

Source: src/display/canvas/Smoothing.js#L80
Since: 3.0.0

isEnabled

<static> isEnabled(context)

Description:

Returns true if the given context has image smoothing enabled, otherwise returns false. Returns null if no smoothing prefix is available.

Parameters:

nametypeoptionaldescription
contextCanvasRenderingContext2D | WebGLRenderingContextNoThe context to check.

Returns: boolean - true if smoothing is enabled on the context, otherwise false. null if not supported.

Source: src/display/canvas/Smoothing.js#L109
Since: 3.0.0

Phaser.Display.Canvas

TouchAction

<static> TouchAction(canvas, [value])

Description:

Sets the touch-action property on the canvas style. Can be used to disable default browser touch actions.

Parameters:

nametypeoptionaldefaultdescription
canvasHTMLCanvasElementNoThe canvas element to have the style applied to.
valuestringYes"'none'"The touch action value to set on the canvas. Set to none to disable touch actions.

Returns: HTMLCanvasElement - The canvas element.

Source: src/display/canvas/TouchAction.js#L7
Since: 3.0.0

UserSelect

<static> UserSelect(canvas, [value])

Description:

Sets the user-select property on the canvas style. Can be used to disable default browser selection actions.

Parameters:

nametypeoptionaldefaultdescription
canvasHTMLCanvasElementNoThe canvas element to have the style applied to.
valuestringYes"'none'"The user-select value to set on the canvas. Set to none to disable default browser text selection and touch callouts.

Returns: HTMLCanvasElement - The canvas element.

Source: src/display/canvas/UserSelect.js#L7
Since: 3.0.0

Phaser.Display.Color

ColorSpectrum

<static> ColorSpectrum([limit])

Description:

Returns an array of Color Objects representing a full color spectrum.

The spectrum colors cycle through the hue wheel in the order: red, yellow, green, cyan, blue, violet, and back to red.

By default this function will return an array with 1024 elements.

However, you can reduce this to a smaller quantity if needed, by specifying the limit parameter. When a limit smaller than 1024 is given, the colors are sampled evenly across the full spectrum so the hue distribution remains uniform regardless of the array size.

Parameters:

nametypeoptionaldefaultdescription
limitnumberYes1024How many colors should be returned? The maximum is 1024 but you can set a smaller quantity if required.

Returns: Array.<Phaser.Types.Display.ColorObject> - An array containing limit parameter number of elements, where each contains a Color Object.

Source: src/display/color/ColorSpectrum.js#L9
Since: 3.50.0

ColorToRGBA

<static> ColorToRGBA(color)

Description:

Converts the given color value into an object containing r, g, b and a properties.

The color value can be a 24-bit RGB integer (e.g. 0xRRGGBB) or a 32-bit ARGB integer (e.g. 0xAARRGGBB). If the value is 24-bit (i.e. does not exceed 0xFFFFFF), the alpha component of the returned object defaults to 255 (fully opaque). Otherwise, the alpha is extracted from the upper 8 bits of the value.

Parameters:

nametypeoptionaldescription
colornumberNoA 24-bit RGB or 32-bit ARGB color integer, optionally including an alpha component in the most-significant byte.

Returns: Phaser.Types.Display.ColorObject - An object containing the parsed color values.

Source: src/display/color/ColorToRGBA.js#L7
Since: 3.0.0

ComponentToHex

<static> ComponentToHex(color)

Description:

Returns a string containing a hex representation of the given color component.

Parameters:

nametypeoptionaldescription
colornumberNoThe color channel to get the hex value for, must be a value between 0 and 255.

Returns: string - A string of length 2 characters, i.e. 255 = ff, 100 = 64.

Source: src/display/color/ComponentToHex.js#L7
Since: 3.0.0

GetColor

<static> GetColor(red, green, blue)

Description:

Packs three separate red, green, and blue color component values into a single 24-bit integer in the format 0xRRGGBB.

Parameters:

nametypeoptionaldescription
rednumberNoThe red color value. A number between 0 and 255.
greennumberNoThe green color value. A number between 0 and 255.
bluenumberNoThe blue color value. A number between 0 and 255.

Returns: number - The packed color value as a 24-bit integer in the format 0xRRGGBB.

Source: src/display/color/GetColor.js#L7
Since: 3.0.0

GetColor32

<static> GetColor32(red, green, blue, alpha)

Description:

Packs four ARGB component values (red, green, blue, and alpha) into a single 32-bit integer in ARGB format.

Parameters:

nametypeoptionaldescription
rednumberNoThe red color value. A number between 0 and 255.
greennumberNoThe green color value. A number between 0 and 255.
bluenumberNoThe blue color value. A number between 0 and 255.
alphanumberNoThe alpha color value. A number between 0 and 255.

Returns: number - The packed 32-bit ARGB color value.

Source: src/display/color/GetColor32.js#L7
Since: 3.0.0

HSLToColor

<static> HSLToColor(h, s, l, [color])

Description:

Converts HSL (hue, saturation and lightness) values to a Phaser Color object.

All three input values should be in the range 0 to 1. If the saturation is 0 the color is treated as achromatic (greyscale). Otherwise the standard HSL-to-RGB algorithm is applied, using the lightness value to derive the intermediate q and p coefficients before delegating each channel to HueToComponent.

Parameters:

nametypeoptionaldescription
hnumberNoThe hue value in the range 0 to 1.
snumberNoThe saturation value in the range 0 to 1.
lnumberNoThe lightness value in the range 0 to 1.
colorPhaser.Display.ColorYesAn optional Color object to populate with the converted values. If not provided, a new Color object is created and returned.

Returns: Phaser.Display.Color - The Color object populated with the RGB values derived from the given h, s and l inputs. This is either the color argument (if provided) or a newly created Color object.

Source: src/display/color/HSLToColor.js#L10
Since: 3.0.0

HSVColorWheel

<static> HSVColorWheel([s], [v])

Description:

Generates an HSV color wheel as an array of 360 ColorObject entries, one for each degree of hue from 0 to 359.

Parameters:

nametypeoptionaldefaultdescription
snumberYes1The saturation, in the range 0 - 1.
vnumberYes1The value, in the range 0 - 1.

Returns: Array.<Phaser.Types.Display.ColorObject> - An array of 360 ColorObject elements, each representing the RGB color at that hue step of the HSV color wheel.

Source: src/display/color/HSVColorWheel.js#L9
Since: 3.0.0

HSVToRGB

<static> HSVToRGB(h, s, v, [out])

Description:

Converts a HSV (hue, saturation and value) color set to RGB.

Conversion formula from https://en.wikipedia.org/wiki/HSL_and_HSV

Assumes HSV values are contained in the set [0, 1].

Parameters:

nametypeoptionaldescription
hnumberNoThe hue, in the range 0 - 1. This is the base color.
snumberNoThe saturation, in the range 0 - 1. This controls how much of the hue will be in the final color, where 1 is fully saturated and 0 will give you a greyscale color.
vnumberNoThe value, in the range 0 - 1. This controls how bright the color is, where 1 is as bright as possible and 0 is black.
outPhaser.Types.Display.ColorObject | Phaser.Display.ColorYesA Color object to store the results in. If not given a new ColorObject will be created.

Returns: Phaser.Types.Display.ColorObject, Phaser.Display.Color - An object with the red, green and blue values set in the r, g and b properties.

Source: src/display/color/HSVToRGB.js#L30
Since: 3.0.0

HexStringToColor

<static> HexStringToColor(hex, [color])

Description:

Converts a hex string into a Phaser Color object.

The hex string can be supplied as '#0033ff' or the short-hand format of '#03f'; it can begin with an optional "#" or "0x", or be unprefixed.

An alpha channel is not supported.

Parameters:

nametypeoptionaldescription
hexstringNoThe hex color value to convert, such as #0033ff or the short-hand format: #03f.
colorPhaser.Display.ColorYesThe color where the new color will be stored. If not defined, a new color object is returned.

Returns: Phaser.Display.Color - A Color object populated by the values of the given string.

Source: src/display/color/HexStringToColor.js#L9
Since: 3.0.0

HueToComponent

<static> HueToComponent(p, q, t)

Description:

Calculates a single RGB channel value from a hue offset and the two intermediate lightness values used during HSL to RGB conversion. Call this function once for each channel (red, green, and blue), passing the appropriate hue offset each time. Based on code by Michael Jackson (https://github.com/mjijackson)

Parameters:

nametypeoptionaldescription
pnumberNoThe first intermediate value derived from the lightness during HSL to RGB conversion.
qnumberNoThe second intermediate value derived from the lightness and saturation during HSL to RGB conversion.
tnumberNoThe hue offset for the color channel being calculated (red, green, or blue).

Returns: number - The RGB channel value for the given hue offset, in the range 0 to 1.

Source: src/display/color/HueToComponent.js#L7
Since: 3.0.0

IntegerToColor

<static> IntegerToColor(input, [color])

Description:

Converts the given color value into an instance of a Color object.

Parameters:

nametypeoptionaldescription
inputnumberNoThe 32-bit integer color value to convert, such as a hex value like 0xff0000 for red.
colorPhaser.Display.ColorYesAn optional Color object to store the result in. If not provided, a new Color object is created and returned.

Returns: Phaser.Display.Color - A Color object containing the red, green, blue, and alpha components extracted from the given integer.

Source: src/display/color/IntegerToColor.js#L10
Since: 3.0.0

IntegerToRGB

<static> IntegerToRGB(color)

Description:

Return the component parts of a color as an Object with the properties alpha, red, green, blue.

If the color value includes an alpha component (0xAARRGGBB), it is extracted and set in the a property. Otherwise, alpha defaults to 255 (fully opaque).

Parameters:

nametypeoptionaldescription
colornumberNoThe color value to convert into a Color object.

Returns: Phaser.Types.Display.ColorObject - An object with the alpha, red, green, and blue values set in the a, r, g, and b properties.

Source: src/display/color/IntegerToRGB.js#L7
Since: 3.0.0

ObjectToColor

<static> ObjectToColor(input, [color])

Description:

Converts an object containing r, g, b and a properties into a Color class instance.

Parameters:

nametypeoptionaldescription
inputPhaser.Types.Display.InputColorObjectNoAn object containing r, g, b and a properties in the range 0 to 255.
colorPhaser.Display.ColorYesThe color where the new color will be stored. If not defined, a new color object is returned.

Returns: Phaser.Display.Color - A Color object.

Source: src/display/color/ObjectToColor.js#L9
Since: 3.0.0

RGBStringToColor

<static> RGBStringToColor(rgb, [color])

Description:

Converts a CSS 'web' string into a Phaser Color object.

The web string can be in the format 'rgb(r,g,b)' or 'rgba(r,g,b,a)' where r/g/b are in the range [0..255] and a is in the range [0..1].

Parameters:

nametypeoptionaldescription
rgbstringNoThe CSS format color string, using the rgb or rgba format.
colorPhaser.Display.ColorYesAn optional Color object to populate with the parsed values. If not provided, a new Color object is created and returned.

Returns: Phaser.Display.Color - The Color object populated with the parsed RGB or RGBA values.

Source: src/display/color/RGBStringToColor.js#L9
Since: 3.0.0

RGBToHSV

<static> RGBToHSV(r, g, b, [out])

Description:

Converts an RGB color value to HSV (hue, saturation and value). Conversion formula from http://en.wikipedia.org/wiki/HSL_color_space. Assumes RGB values are contained in the set [0, 255] and returns h, s and v in the set [0, 1]. Based on code by Michael Jackson (https://github.com/mjijackson)

Parameters:

nametypeoptionaldescription
rnumberNoThe red color value. A number between 0 and 255.
gnumberNoThe green color value. A number between 0 and 255.
bnumberNoThe blue color value. A number between 0 and 255.
outPhaser.Types.Display.HSVColorObject | Phaser.Display.ColorYesAn object to store the color values in. If not given an HSV Color Object will be created.

Returns: Phaser.Types.Display.HSVColorObject, Phaser.Display.Color - An object with the properties h, s and v set.

Source: src/display/color/RGBToHSV.js#L7
Since: 3.0.0

RGBToString

<static> RGBToString(r, g, b, [a], [prefix])

Description:

Converts the given red, green, blue, and alpha color component values into a hex color string.

When using the # prefix the result is a 6-character CSS-compatible hex string in #rrggbb format. The alpha value is not included in this format.

When using the 0x prefix the result is an 8-character ARGB hex string in 0xaarrggbb format, which includes the alpha component as the most significant byte.

Parameters:

nametypeoptionaldefaultdescription
rnumberNoThe red color value. A number between 0 and 255.
gnumberNoThe green color value. A number between 0 and 255.
bnumberNoThe blue color value. A number between 0 and 255.
anumberYes255The alpha value. A number between 0 and 255.
prefixstringYes"#"The prefix of the string. Either # or 0x.

Returns: string - A hex color string in either #rrggbb or 0xaarrggbb format, depending on the prefix.

Source: src/display/color/RGBToString.js#L9
Since: 3.0.0

RandomRGB

<static> RandomRGB([min], [max])

Description:

Creates a new Color object where the r, g, and b values have been set to random values based on the given min max values.

Parameters:

nametypeoptionaldefaultdescription
minnumberYes0The minimum value to set the random range from (between 0 and 255)
maxnumberYes255The maximum value to set the random range from (between 0 and 255)

Returns: Phaser.Display.Color - A Color object.

Source: src/display/color/RandomRGB.js#L10
Since: 3.0.0

ValueToColor

<static> ValueToColor(input, [color])

Description:

Converts the given source color value into an instance of a Color class. The value can be a string (either prefixed with rgb for an RGB color string, or a hex color string), a number representing a packed RGB integer, or a plain object with r, g, and b properties.

Parameters:

nametypeoptionaldescription
inputstring | numberPhaser.Types.Display.InputColorObjectNo
colorPhaser.Display.ColorYesAn existing Color object to store the result in. If not provided, a new Color object is created and returned.

Returns: Phaser.Display.Color - A Color object containing the converted color value.

Source: src/display/color/ValueToColor.js#L12
Since: 3.0.0

Phaser.Display.Color.Interpolate

RGBWithRGB

<static> RGBWithRGB(r1, g1, b1, r2, g2, b2, [length], [index])

Description:

Interpolates between the two given RGB color values over the length supplied.

Parameters:

nametypeoptionaldefaultdescription
r1numberNoRed value.
g1numberNoGreen value.
b1numberNoBlue value.
r2numberNoRed value.
g2numberNoGreen value.
b2numberNoBlue value.
lengthnumberYes100Distance to interpolate over.
indexnumberYes0Index to start from.

Returns: Phaser.Types.Display.ColorObject - An object containing the interpolated color values.

Source: src/display/color/Interpolate.js#L17
Since: 3.0.0

HSVWithHSV

<static> HSVWithHSV(h1, s1, v1, h2, s2, v2, [length], [index], [sign])

Description:

Interpolates between the two given HSV color ranges over the length supplied. The sign parameter controls the direction of hue interpolation: 0 finds the nearest path, a positive value always increases hue, and a negative value always decreases hue.

Parameters:

nametypeoptionaldefaultdescription
h1numberNoHue of the first color (0 to 1).
s1numberNoSaturation of the first color (0 to 1).
v1numberNoValue (brightness) of the first color (0 to 1).
h2numberNoHue of the second color (0 to 1).
s2numberNoSaturation of the second color (0 to 1).
v2numberNoValue (brightness) of the second color (0 to 1).
lengthnumberYes100Distance to interpolate over.
indexnumberYes0Index to start from.
signnumberYes0Hue interpolation direction. 0 = nearest, positive = always increase, negative = always decrease.

Returns: Phaser.Types.Display.ColorObject - An object containing the interpolated color values.

Source: src/display/color/Interpolate.js#L55
Since: 4.0.0

ColorWithColor

<static> ColorWithColor(color1, color2, [length], [index], [hsv], [hsvSign])

Description:

Interpolates between the two given color objects over the length supplied.

Parameters:

nametypeoptionaldefaultdescription
color1Phaser.Display.ColorNoThe first Color object.
color2Phaser.Display.ColorNoThe second Color object.
lengthnumberYes100Distance to interpolate over.
indexnumberYes0Index to start from.
hsvbooleanYesfalseWhether to interpolate in HSV.
hsvSignnumberYes0Preferred direction for HSV interpolation. 0 is nearest, negative always decreases hue, positive always increases hue.

Returns: Phaser.Types.Display.ColorObject - An object containing the interpolated color values.

Source: src/display/color/Interpolate.js#L102
Since: 3.0.0

ColorWithRGB

<static> ColorWithRGB(color, r, g, b, [length], [index])

Description:

Interpolates between the Color object and color values over the length supplied.

Parameters:

nametypeoptionaldefaultdescription
colorPhaser.Display.ColorNoThe Color object.
rnumberNoRed value.
gnumberNoGreen value.
bnumberNoBlue value.
lengthnumberYes100Distance to interpolate over.
indexnumberYes0Index to start from.

Returns: Phaser.Types.Display.ColorObject - An object containing the interpolated color values.

Source: src/display/color/Interpolate.js#L132
Since: 3.0.0