You’re reading the docs for Phaser v3.90.0. The latest is Phaser v4.1.0.

Phaser.Display.Align.In

Phaser.Display

BottomCenter

staticBottomCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned in the bottom 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/BottomCenter.js#L12
Since: 3.0.0

BottomLeft

staticBottomLeft(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes 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

staticBottomRight(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned in the bottom right 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/BottomRight.js#L12
Since: 3.0.0

Center

staticCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes 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

staticLeftCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned in the left 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/LeftCenter.js#L12
Since: 3.0.0

QuickSet

staticQuickSet(child, alignIn, position, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned relative to the other.

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

staticRightCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned in the right 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/RightCenter.js#L12
Since: 3.0.0

TopCenter

staticTopCenter(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned in the top 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/TopCenter.js#L12
Since: 3.0.0

TopLeft

staticTopLeft(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned in the top 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/TopLeft.js#L12
Since: 3.0.0

TopRight

staticTopRight(gameObject, alignIn, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned in the top right 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/TopRight.js#L12
Since: 3.0.0

Phaser.Display.Align.To

BottomCenter

staticBottomCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the bottom center position of the other.

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

staticBottomLeft(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the bottom left position of the other.

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

staticBottomRight(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the bottom right position of the other.

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

staticLeftBottom(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the left bottom position of the other.

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

staticLeftCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the left center position of the other.

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

staticLeftTop(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the left top position of the other.

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

staticQuickSet(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.
offsetYnumberYes0Optional vertical offset from the position.

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

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

RightBottom

staticRightBottom(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the right bottom position of the other.

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

staticRightCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the right center position of the other.

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

staticRightTop(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the right top position of the other.

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

staticTopCenter(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the top center position of the other.

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

staticTopLeft(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the top left position of the other.

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

staticTopRight(gameObject, alignTo, [offsetX], [offsetY])

Description:

Takes given Game Object and aligns it so that it is positioned next to the top right position of the other.

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

staticCenterOn(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

staticGetBottom(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

staticGetBounds(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

staticGetCenterX(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

staticGetCenterY(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

staticGetLeft(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

staticGetOffsetX(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

staticGetOffsetY(gameObject)

Description:

Returns the amount the Game Object is visually offset from its y coordinate.

This is the same as width * 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

staticGetRight(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

staticGetTop(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

staticSetBottom(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

staticSetCenterX(gameObject, x)

Description:

Positions the Game Object so that the center top 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

staticSetCenterY(gameObject, y)

Description:

Positions the Game Object so that the center top 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

staticSetLeft(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

staticSetRight(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/SetRight.js#L7
Since: 3.0.0

SetTop

staticSetTop(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

staticsetCrisp(canvas)

Description:

Sets the CSS image-rendering property on the given canvas to be 'crisp' (aka 'optimize contrast' on webkit).

Parameters:

nametypeoptionaldescription
canvasHTMLCanvasElementNoThe canvas object to have the style set on.

Returns: HTMLCanvasElement - The canvas.

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

setBicubic

staticsetBicubic(canvas)

Description:

Sets the CSS image-rendering property on the given canvas to be 'bicubic' (aka 'auto').

Parameters:

nametypeoptionaldescription
canvasHTMLCanvasElementNoThe canvas object to have the style set on.

Returns: HTMLCanvasElement - The canvas.

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

Phaser.Display.Canvas.CanvasPool

create

staticcreate(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

staticcreate2D(parent, [width], [height])

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.

Returns: HTMLCanvasElement - The created canvas.

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

createWebGL

staticcreateWebGL(parent, [width], [height])

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.

Returns: HTMLCanvasElement - The created WebGL canvas.

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

first

staticfirst([canvasType])

Description:

Gets the first free canvas index 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#L125
Since: 3.0.0

remove

staticremove(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#L157
Since: 3.0.0

total

statictotal()

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#L182
Since: 3.0.0

free

staticfree()

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#L205
Since: 3.0.0

disableSmoothing

staticdisableSmoothing()

Description:

Disable context smoothing on any new Canvas element created.

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

enableSmoothing

staticenableSmoothing()

Description:

Enable context smoothing on any new Canvas element created.

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

Phaser.Display.Canvas.Smoothing

getPrefix

staticgetPrefix(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#L16
Since: 3.0.0

enable

staticenable(context)

Description:

Sets the Image Smoothing property on the given context. Set to false to disable image smoothing.

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#L43
Since: 3.0.0

disable

staticdisable(context)

Description:

Sets the Image Smoothing property on the given context. Set to false to disable image smoothing.

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#L72
Since: 3.0.0

isEnabled

staticisEnabled(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#L101
Since: 3.0.0

Phaser.Display.Canvas

TouchAction

staticTouchAction(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

staticUserSelect(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 touch callout value to set on the canvas. Set to none to disable touch callouts.

Returns: HTMLCanvasElement - The canvas element.

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

Phaser.Display.Color

ColorSpectrum

staticColorSpectrum([limit])

Description:

Return an array of Colors in a Color Spectrum.

The spectrum colors flow in the order: red, yellow, green, blue.

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

However, you can reduce this to a smaller quantity if needed, by specitying the limit parameter.

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

staticColorToRGBA(color)

Description:

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

Parameters:

nametypeoptionaldescription
colornumberNoA color value, optionally including the alpha value.

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

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

ComponentToHex

staticComponentToHex(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

staticGetColor(red, green, blue)

Description:

Given 3 separate color values this will return an integer representation of it.

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 combined color value.

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

GetColor32

staticGetColor32(red, green, blue, alpha)

Description:

Given an alpha and 3 color values this will return an integer representation of it.

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 combined color value.

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

HSLToColor

staticHSLToColor(h, s, l)

Description:

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

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.

Returns: Phaser.Display.Color - A Color object created from the results of the h, s and l values.

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

HSVColorWheel

staticHSVColorWheel([s], [v])

Description:

Generates an HSV color wheel which is an array of 360 Color objects, for each step of the wheel.

Parameters:

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

Returns: Array.<Phaser.Types.Display.ColorObject> - An array containing 360 ColorObject elements, where each element contains a Color object corresponding to the color at that point in the HSV color wheel.

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

HSVToRGB

staticHSVToRGB(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 white.
vnumberNoThe value, in the range 0 - 1. This controls how dark 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

staticHexStringToColor(hex)

Description:

Converts a hex string into a Phaser Color object.

The hex string can 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.

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

staticHueToComponent(p, q, t)

Description:

Converts a hue to an RGB color.

Based on code by Michael Jackson (https://github.com/mjijackson)

Parameters:

nametypeoptionaldescription
pnumberNoNo description provided
qnumberNoNo description provided
tnumberNoNo description provided

Returns: number - The combined color value.

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

IntegerToColor

staticIntegerToColor(input)

Description:

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

Parameters:

nametypeoptionaldescription
inputnumberNoThe color value to convert into a Color object.

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

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

IntegerToRGB

staticIntegerToRGB(input)

Description:

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

Alpha will only be set if it exists in the given color (0xAARRGGBB)

Parameters:

nametypeoptionaldescription
inputnumberNoThe color value to convert into a Color object.

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

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

ObjectToColor

staticObjectToColor(input)

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.

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

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

RGBStringToColor

staticRGBStringToColor(rgb)

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.

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

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

RGBToHSV

staticRGBToHSV(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

staticRGBToString(r, g, b, [a], [prefix])

Description:

Converts the color values into an HTML compatible color string, prefixed with either # or 0x.

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 string-based representation of the color values.

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

RandomRGB

staticRandomRGB([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

staticValueToColor(input)

Description:

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

The value can be either a string, prefixed with rgb or a hex string, a number or an Object.

Parameters:

nametypeoptionaldescription
inputstring | numberPhaser.Types.Display.InputColorObjectNo

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

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

Phaser.Display.Color.Interpolate

RGBWithRGB

staticRGBWithRGB(r1, g1, b1, r2, g2, b2, [length], [index])

Description:

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

Parameters:

nametypeoptionaldefaultdescription
r1numberNoRed value.
g1numberNoBlue value.
b1numberNoGreen value.
r2numberNoRed value.
g2numberNoBlue value.
b2numberNoGreen 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#L16
Since: 3.0.0

ColorWithColor

staticColorWithColor(color1, color2, [length], [index])

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.

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

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

ColorWithRGB

staticColorWithRGB(color1, r, g, b, [length], [index])

Description:

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

Parameters:

nametypeoptionaldefaultdescription
color1Phaser.Display.ColorNoThe first Color object.
rnumberNoRed value.
gnumberNoBlue value.
bnumberNoGreen 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#L77
Since: 3.0.0