Skip to main content
Version: Phaser v4.0.0-rc.6

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

<static> createWebGL(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

<static> disableSmoothing()

Description:

Disable context smoothing on any new Canvas element created.

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


enableSmoothing

<static> enableSmoothing()

Description:

Enable context smoothing on any new Canvas element created.

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


first

<static> first([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

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