Namespace: CanvasPool

Phaser.Display.Canvas. CanvasPool

The CanvasPool is a global static object, that allows Phaser to recycle and pool 2D Context Canvas DOM elements.
It does not pool WebGL Contexts, because once the context options are set they cannot be modified again,
which is useless for some of the Phaser pipelines / renderer.

This singleton is instantiated as soon as Phaser loads, before a Phaser.Game instance has even been created.
Which means all instances of Phaser Games on the same page can share the one single pool.

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 16)

Methods


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

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

Parameters:
Name Type Argument Default Description
parent *

The parent of the Canvas object.

width integer <optional>
1

The width of the Canvas.

height integer <optional>
1

The height of the Canvas.

canvasType integer <optional>
Phaser.CANVAS

The type of the Canvas. Either Phaser.CANVAS or Phaser.WEBGL.

selfParent boolean <optional>
false

Use the generated Canvas element as the parent?

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 29)
Returns:

[description]

Type
HTMLCanvasElement

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

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

Parameters:
Name Type Argument Default Description
parent *

The parent of the Canvas object.

width integer <optional>
1

The width of the Canvas.

height integer <optional>
1

The height of the Canvas.

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 91)
Returns:

[description]

Type
HTMLCanvasElement

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

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

Parameters:
Name Type Argument Default Description
parent *

The parent of the Canvas object.

width integer <optional>
1

The width of the Canvas.

height integer <optional>
1

The height of the Canvas.

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 108)
Returns:

[description]

Type
HTMLCanvasElement

<static> disableSmoothing()

Disable context smoothing on any new Canvas element created.

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 218)

<static> enableSmoothing()

Enable context smoothing on any new Canvas element created.

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 229)

<static> first( [canvasType])

Gets the first free canvas index from the pool.

Parameters:
Name Type Argument Default Description
canvasType integer <optional>
Phaser.CANVAS

The type of the Canvas. Either Phaser.CANVAS or Phaser.WEBGL.

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 125)
Returns:

[description]

Type
HTMLCanvasElement

<static> free()

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

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 205)
Returns:

[description]

Type
integer

<static> remove(parent)

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:
Name Type Description
parent *

[description]

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 157)

<static> total()

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

Since: 3.0.0
Source: src/display/canvas/CanvasPool.js (Line 182)
Returns:

[description]

Type
integer