Skip to main content
Version: Phaser v4.0.0

Phaser.Display.Canvas.CanvasPool

Scope: static

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

Static functions

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


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


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


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


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