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

Phaser.Display.Canvas.CanvasPool

Scope: static

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

Static functions

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


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


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


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


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