Optional value to use, if not provided, white is used.
Static
Readonly
sharedStatic shared Color instance used for utility operations. This is a singleton color object that can be reused to avoid creating unnecessary Color instances.
You should be careful when using this shared instance, as it is mutable and can be changed by any code that uses it.
It is best used for one-off color operations or temporary transformations. For persistent colors, create your own Color instance instead.
import { Color } from 'pixi.js';
// Use shared instance for one-off color operations
Color.shared.setValue(0xff0000);
const redHex = Color.shared.toHex(); // "#ff0000"
const redRgb = Color.shared.toRgbArray(); // [1, 0, 0]
// Temporary color transformations
const colorNumber = Color.shared
.setValue('#ff0000') // Set to red
.setAlpha(0.5) // Make semi-transparent
.premultiply(0.8) // Apply premultiplication
.toNumber(); // Convert to number
// Chain multiple operations
const result = Color.shared
.setValue(someColor)
.multiply(tintColor)
.toPremultiplied(alpha);
The current color source. This property allows getting and setting the color value while preserving the original format where possible.
When setting:
Color
instance copies its source and componentsnull
throws an ErrorWhen getting:
null
if color was modified by Color.multiply or Color.premultiply// Setting different color formats
const color = new Color();
color.value = 0xff0000; // Hex number
color.value = '#ff0000'; // Hex string
color.value = [1, 0, 0]; // RGB array
color.value = [1, 0, 0, 0.5]; // RGBA array
color.value = { r: 1, g: 0, b: 0 }; // RGB object
// Copying from another color
const red = new Color('red');
color.value = red; // Copies red's components
// Getting the value
console.log(color.value); // Returns original format
// After modifications
color.multiply([0.5, 0.5, 0.5]);
console.log(color.value); // Returns null
Multiply with another color.
This action is destructive and modifies the original color.
The color to multiply by. Accepts any valid color format:
this - The Color instance for chaining
Converts color to a premultiplied alpha format.
This action is destructive and modifies the original color.
The alpha value to multiply by (0-1)
Optional
applyToRGB: boolean = trueWhether to premultiply RGB channels
The Color instance for chaining
// Basic premultiplication
const color = new Color('red');
color.premultiply(0.5); // 50% transparent red with premultiplied RGB
// Alpha only (RGB unchanged)
color.premultiply(0.5, false); // 50% transparent, original RGB
// Chain with other operations
color
.multiply(0x808080)
.premultiply(0.5)
.toNumber();
Set alpha (transparency) value while preserving color components.
Provides a chainable interface for setting alpha.
Alpha value between 0 (fully transparent) and 1 (fully opaque)
The Color instance for chaining
Sets the color value and returns the instance for chaining.
This is a chainable version of setting the value
property.
The color to set. Accepts various formats:
The Color instance for chaining
// Basic usage
const color = new Color();
color.setValue('#ff0000')
.setAlpha(0.5)
.premultiply(0.8);
// Different formats
color.setValue(0xff0000); // Hex number
color.setValue('#ff0000'); // Hex string
color.setValue([1, 0, 0]); // RGB array
color.setValue([1, 0, 0, 0.5]); // RGBA array
color.setValue({ r: 1, g: 0, b: 0 }); // RGB object
// Copy from another color
const red = new Color('red');
color.setValue(red);
Color.value For the underlying value property
Convert to an [R, G, B, A] array of normalized floats (numbers from 0.0 to 1.0).
Optional
out: TOptional output array. If not provided, a cached array will be used and returned.
Array containing RGBA components as floats between 0-1
// Basic usage
new Color('white').toArray(); // returns [1, 1, 1, 1]
new Color('red').toArray(); // returns [1, 0, 0, 1]
// With alpha
new Color('rgba(255,0,0,0.5)').toArray(); // returns [1, 0, 0, 0.5]
// Using custom output array
const rgba = new Float32Array(4);
new Color('blue').toArray(rgba); // rgba is now [0, 0, 1, 1]
Convert to a BGR number.
Useful for platforms that expect colors in BGR format.
The color as a 24-bit BGR integer
Convert to a hexadecimal string (6 characters).
A CSS-compatible hex color string (e.g., "#ff0000")
import { Color } from 'pixi.js';
// Basic colors
new Color('red').toHex(); // returns "#ff0000"
new Color('white').toHex(); // returns "#ffffff"
new Color('black').toHex(); // returns "#000000"
// From different formats
new Color(0xff0000).toHex(); // returns "#ff0000"
new Color([1, 0, 0]).toHex(); // returns "#ff0000"
new Color({ r: 1, g: 0, b: 0 }).toHex(); // returns "#ff0000"
Convert to a hexadecimal string with alpha (8 characters).
A CSS-compatible hex color string with alpha (e.g., "#ff0000ff")
import { Color } from 'pixi.js';
// Fully opaque colors
new Color('red').toHexa(); // returns "#ff0000ff"
new Color('white').toHexa(); // returns "#ffffffff"
// With transparency
new Color('rgba(255, 0, 0, 0.5)').toHexa(); // returns "#ff00007f"
new Color([1, 0, 0, 0]).toHexa(); // returns "#ff000000"
Convert to a hexadecimal number in little endian format (e.g., BBGGRR).
Useful for platforms that expect colors in little endian byte order.
The color as a number in little endian format (BBGGRR)
import { Color } from 'pixi.js';
// Convert RGB color to little endian format
new Color(0xffcc99).toLittleEndianNumber(); // returns 0x99ccff
// Common use cases:
const color = new Color('orange');
const leColor = color.toLittleEndianNumber(); // Swaps byte order for LE systems
// Multiple conversions
const colors = {
normal: 0xffcc99,
littleEndian: new Color(0xffcc99).toLittleEndianNumber(), // 0x99ccff
backToNormal: new Color(0x99ccff).toLittleEndianNumber() // 0xffcc99
};
Color.toBgrNumber For BGR format without byte swapping
Returns the color as a 32-bit premultiplied alpha integer.
Format: 0xAARRGGBB
The alpha value to multiply by (0-1)
Optional
applyToRGB: boolean = trueWhether to premultiply RGB channels
The premultiplied color as a 32-bit integer
// Convert to premultiplied format
const color = new Color('red');
// Full opacity (0xFFRRGGBB)
color.toPremultiplied(1.0); // 0xFFFF0000
// 50% transparency with premultiplied RGB
color.toPremultiplied(0.5); // 0x7F7F0000
// 50% transparency without RGB premultiplication
color.toPremultiplied(0.5, false); // 0x7FFF0000
Convert to a RGB color object with normalized components (0-1).
Alpha component is omitted in the output.
An RGB object with normalized components
Convert to a RGBA color object with normalized components (0-1).
An RGBA object with normalized components
import { Color } from 'pixi.js';
// Convert colors to RGBA objects
new Color('white').toRgba(); // returns { r: 1, g: 1, b: 1, a: 1 }
new Color('#ff0000').toRgba(); // returns { r: 1, g: 0, b: 0, a: 1 }
// With transparency
new Color('rgba(255,0,0,0.5)').toRgba(); // returns { r: 1, g: 0, b: 0, a: 0.5 }
Convert to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0).
Optional
out: TOptional output array. If not provided, a cached array will be used and returned.
Array containing RGB components as floats between 0-1
Convert to a CSS-style rgba string representation.
RGB components are scaled to 0-255 range, alpha remains 0-1.
A CSS-compatible rgba string
Convert to an [R, G, B] array of clamped uint8 values (0 to 255).
Optional
out: TOptional output array. If not provided, a cached array will be used and returned.
Array containing RGB components as integers between 0-255
// Basic usage
new Color('white').toUint8RgbArray(); // returns [255, 255, 255]
new Color('#ff0000').toUint8RgbArray(); // returns [255, 0, 0]
// Using custom output array
const rgb = new Uint8Array(3);
new Color('blue').toUint8RgbArray(rgb); // rgb is now [0, 0, 255]
// Using different array types
new Color('red').toUint8RgbArray(new Uint8ClampedArray(3)); // [255, 0, 0]
new Color('red').toUint8RgbArray([]); // [255, 0, 0]
Static
isCheck if a value can be interpreted as a valid color format. Supports all color formats that can be used with the Color class.
Value to check
True if the value can be used as a color
import { Color } from 'pixi.js';
// CSS colors and hex values
Color.isColorLike('red'); // true
Color.isColorLike('#ff0000'); // true
Color.isColorLike(0xff0000); // true
// Arrays (RGB/RGBA)
Color.isColorLike([1, 0, 0]); // true
Color.isColorLike([1, 0, 0, 0.5]); // true
// TypedArrays
Color.isColorLike(new Float32Array([1, 0, 0])); // true
Color.isColorLike(new Uint8Array([255, 0, 0])); // true
Color.isColorLike(new Uint8ClampedArray([255, 0, 0])); // true
// Object formats
Color.isColorLike({ r: 1, g: 0, b: 0 }); // true (RGB)
Color.isColorLike({ r: 1, g: 0, b: 0, a: 0.5 }); // true (RGBA)
Color.isColorLike({ h: 0, s: 100, l: 50 }); // true (HSL)
Color.isColorLike({ h: 0, s: 100, l: 50, a: 0.5 }); // true (HSLA)
Color.isColorLike({ h: 0, s: 100, v: 100 }); // true (HSV)
Color.isColorLike({ h: 0, s: 100, v: 100, a: 0.5 });// true (HSVA)
// Color instances
Color.isColorLike(new Color('red')); // true
// Invalid values
Color.isColorLike(null); // false
Color.isColorLike(undefined); // false
Color.isColorLike({}); // false
Color.isColorLike([]); // false
Color.isColorLike('not-a-color'); // false
Checks for the following formats:
Color utility class for managing colors in various formats. Provides a unified way to work with colors across your PixiJS application.
Features:
Example
Remarks
The Color class automatically normalizes all color values internally:
Since
7.2.0