Phaser API Documentation

  Version: 
getPixels([x], [y], [width], [height])

Description:

Returns an array containing all of the pixels in the given region.

If the requested region extends outside the bounds of this CanvasTexture, the region is truncated to fit.

If you have drawn anything to this CanvasTexture since it was created you must call CanvasTexture.update to refresh the array buffer, otherwise this may return out of date color values, or worse - throw a run-time error as it tries to access an array element that doesn't exist.

Parameters:

name type arguments description
x number <optional>

The x coordinate of the top-left of the region. Must lay within the dimensions of this CanvasTexture and be an integer.

y number <optional>

The y coordinate of the top-left of the region. Must lay within the dimensions of this CanvasTexture and be an integer.

width number <optional>

The width of the region to get. Must be an integer. Defaults to the canvas width if not given.

height number <optional>

The height of the region to get. Must be an integer. If not given will be set to the width.

Returns:
Description:

A 2d array of Pixel objects.

Type:
Examples:
Since: 3.16.0