Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord
Namespace: CanvasPool
Phaser.Display.Canvas.CanvasPool

Methods

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

Description:

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

Parameters:

name type arguments Default description
parent *

The parent of the Canvas object.

width number <optional> 1

The width of the Canvas.

height number <optional> 1

The height of the Canvas.

canvasType number <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?

Returns:
Description:

The canvas element that was created or pulled from the pool

Type:
  • HTMLCanvasElement
Examples:
Since: 3.0.0
Focus
Focus
<static> create2D(parent, [width], [height])
Focus
Focus

Description:

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

Parameters:

name type arguments Default description
parent *

The parent of the Canvas object.

width number <optional> 1

The width of the Canvas.

height number <optional> 1

The height of the Canvas.

Returns:
Description:

The created canvas.

Type:
  • HTMLCanvasElement
Examples:
Since: 3.0.0
Focus
Focus
<static> createWebGL(parent, [width], [height])
Focus
Focus

Description:

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

Parameters:

name type arguments Default description
parent *

The parent of the Canvas object.

width number <optional> 1

The width of the Canvas.

height number <optional> 1

The height of the Canvas.

Returns:
Description:

The created WebGL canvas.

Type:
  • HTMLCanvasElement
Examples:
Since: 3.0.0
Focus
Focus
<static> first([canvasType])
Focus
Focus

Description:

Gets the first free canvas index from the pool.

Parameters:

name type arguments Default description
canvasType number <optional> Phaser.CANVAS

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

Returns:
Description:

The first free canvas, or null if a WebGL canvas was requested or if the pool doesn't have free canvases.

Type:
  • HTMLCanvasElement
Examples:
Since: 3.0.0
Focus
Focus
<static> remove(parent)
Focus
Focus

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:

name type description
parent *

The canvas or the parent of the canvas to free.

Examples:
Since: 3.0.0
Focus
Focus
<static> total()
Focus
Focus

Description:

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

Returns:
Description:

The number of used canvases.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<static> free()
Focus
Focus

Description:

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

Returns:
Description:

The number of free canvases.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<static> disableSmoothing()
Focus
Focus

Description:

Disable context smoothing on any new Canvas element created.

Examples:
Since: 3.0.0
Focus
Focus
<static> enableSmoothing()
Focus
Focus

Description:

Enable context smoothing on any new Canvas element created.

Examples:
Since: 3.0.0
Focus
Focus