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

Phaser . Display . ColorMatrix

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

Phaser . Display . ColorMatrix

The ColorMatrix class creates a 5x4 matrix that can be used in shaders and graphics operations. It provides methods required to modify the color values, such as adjusting the brightness, setting a sepia tone, hue rotation and more.

Use the method getData to return a Float32Array containing the current color values.

Constructor:

new ColorMatrix()
Since: 3.50.0
Source: src/display/ColorMatrix.js (Line 9)

Members

<private> _dirty: boolean
Focus
Focus

Description:

Is the ColorMatrix array dirty?

Type:
boolean
Since: 3.50.0
Focus
Focus
<private> _matrix: Array.<number>
Focus
Focus

Description:

Internal ColorMatrix array.

Type:
Array.<number>
Since: 3.50.0
Focus
Focus
alpha: number
Focus
Focus

Description:

The value that determines how much of the original color is used when mixing the colors. A value between 0 (all original) and 1 (all final)

Type:
number
Since: 3.50.0
Focus
Focus
<private> data: Float32Array
Focus
Focus

Description:

The matrix data as a Float32Array.

Returned by the getData method.

Type:
Float32Array
Since: 3.50.0
Focus
Focus

Methods

blackWhite([multiply])
Focus
Focus

Description:

Sets this ColorMatrix to be black and white.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
brightness([value], [multiply])
Focus
Focus

Description:

Changes the brightness of this ColorMatrix by the given amount.

Parameters:

name type arguments Default description
value number <optional> 0

The amount of brightness to apply to this ColorMatrix. Between 0 (black) and 1.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
brown([multiply])
Focus
Focus

Description:

Applies a brown tone to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
contrast([value], [multiply])
Focus
Focus

Description:

Change the contrast of this ColorMatrix by the amount given.

Parameters:

name type arguments Default description
value number <optional> 0

The amount of contrast to apply to this ColorMatrix.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
desaturateLuminance([multiply])
Focus
Focus

Description:

Apply a desaturated luminance to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
getData()
Focus
Focus

Description:

Gets the ColorMatrix as a Float32Array.

Can be used directly as a 1fv shader uniform value.

Returns:
Description:

The ColorMatrix as a Float32Array.

Type:
  • Float32Array
Examples:
Since: 3.50.0
Focus
Focus
grayscale([value], [multiply])
Focus
Focus

Description:

Sets this ColorMatrix to be grayscale.

Parameters:

name type arguments Default description
value number <optional> 1

The grayscale scale (0 is black).

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
hue([rotation], [multiply])
Focus
Focus

Description:

Rotates the hues of this ColorMatrix by the value given.

Parameters:

name type arguments Default description
rotation number <optional> 0

The amount of hue rotation to apply to this ColorMatrix, in degrees.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
kodachrome([multiply])
Focus
Focus

Description:

Applies a kodachrome color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
lsd([multiply])
Focus
Focus

Description:

Applies a trippy color tone to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
multiply(a)
Focus
Focus

Description:

Multiplies the two given matrices.

Parameters:

name type description
a Array.<number>

The 5x4 array to multiply with ColorMatrix._matrix.

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
negative([multiply])
Focus
Focus

Description:

Converts this ColorMatrix to have negative values.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
night([intensity], [multiply])
Focus
Focus

Description:

Applies a night vision tone to this ColorMatrix.

Parameters:

name type arguments Default description
intensity number <optional> 0.1

The intensity of this effect.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
polaroid([multiply])
Focus
Focus

Description:

Applies a polaroid color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
reset()
Focus
Focus

Description:

Resets the ColorMatrix.

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
saturate([value], [multiply])
Focus
Focus

Description:

Changes the saturation of this ColorMatrix by the given amount.

Parameters:

name type arguments Default description
value number <optional> 0

The amount of saturation to apply to this ColorMatrix.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
saturation([multiply])
Focus
Focus

Description:

Desaturates this ColorMatrix (removes color from it).

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
sepia([multiply])
Focus
Focus

Description:

Applies a sepia tone to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
set(value)
Focus
Focus

Description:

Sets this ColorMatrix from the given array of color values.

Parameters:

name type description
value Array.<number>

The ColorMatrix values to set.

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
shiftToBGR([multiply])
Focus
Focus

Description:

Shifts the values of this ColorMatrix into BGR order.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
technicolor([multiply])
Focus
Focus

Description:

Applies a technicolor color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus
vintagePinhole([multiply])
Focus
Focus

Description:

Applies a vintage pinhole color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Examples:
Since: 3.50.0
Focus
Focus