Namespace: utils

PIXI.utils

Generalized convenience utilities for PIXI.

Example

// Extend PIXI's internal Event Emitter.
class MyEmitter extends PIXI.utils.EventEmitter {
  constructor() {
     super();
     console.log("Emitter created!");
  }
}

// Get info on current device
console.log(PIXI.utils.isMobile);

// Convert hex color to string
console.log(PIXI.utils.hex2string(0xff00ff)); // returns: "#ff00ff"

Classes

EventEmitter

Members

PIXI.utils._saidHello boolean Deprecated : since 4.1.0 static

See:

PIXI.utils.premultiplyBlendMode Array.<Array.<number>> staticconstant

maps premultiply flag and blendMode to adjusted blendMode

Methods

PIXI.utils.canUseNewCanvasBlendModes ()boolean Deprecated static

See:
Returns:
Type Description
boolean Can use blend modes.

PIXI.utils.clearTextureCache () static

Removes all textures from cache, but does not destroy them

PIXI.utils.correctBlendMode (blendMode, premultiplied)number static

changes blendMode according to texture format

Name Type Description
blendMode number

supposed blend mode

premultiplied boolean

whether source is premultiplied

Returns:
Type Description
number true blend mode for this texture

PIXI.utils.decomposeDataUri (dataUri)PIXI.utils~DecomposedDataUri | undefined static

Split a data URI into components. Returns undefined if parameter dataUri is not a valid data URI.

Name Type Description
dataUri string

the data URI to check

Returns:
Type Description
PIXI.utils~DecomposedDataUri | undefined The decomposed data uri or undefined

PIXI.utils.destroyTextureCache () static

Destroys all texture in the cache

PIXI.utils.earcut (vertices, holes, dimensions)Array.<number> static

Name Type Default Description
vertices Array.<number>

A flat array of vertice coordinates

holes Array.<number> optional

An array of hole indices

dimensions number 2 optional

The number of coordinates per vertice in the input array

See:
Returns:
Type Description
Array.<number> Triangulated polygon

PIXI.utils.exports.premultiplyRgba (rgb, alpha, out, premultiply)Float32Array static

combines rgb and alpha to out array

Name Type Default Description
rgb Float32Array | Array.<number>

input rgb

alpha number

alpha param

out Float32Array optional

output

premultiply boolean true optional

do premultiply it

Returns:
Type Description
Float32Array vec4 rgba

PIXI.utils.exports.premultiplyTint (tint, alpha)number static

premultiplies tint

Name Type Description
tint number

integet RGB

alpha number

floating point alpha (0.0-1.0)

Returns:
Type Description
number tint multiplied by alpha

PIXI.utils.exports.premultiplyTintToRgba (tint, alpha, out, premultiply)Float32Array static

converts integer tint and float alpha to vec4 form, premultiplies by default

Name Type Default Description
tint number

input tint

alpha number

alpha param

out Float32Array optional

output

premultiply boolean true optional

do premultiply it

Returns:
Type Description
Float32Array vec4 rgba

PIXI.utils.getResolutionOfUrl (url, defaultValue)number static

get the resolution / device pixel ratio of an asset by looking for the prefix used by spritesheets and image urls

Name Type Default Description
url string

the image path

defaultValue number 1 optional

the defaultValue if no filename prefix is set.

Returns:
Type Description
number resolution / device pixel ratio of an asset

PIXI.utils.getSvgSize (svgString)PIXI.utils~Size | undefined static

Get size from an svg string using regexp.

Name Type Description
svgString string

a serialized svg element

Returns:
Type Description
PIXI.utils~Size | undefined image extension

PIXI.utils.getUrlFileExtension (url)string | undefined static

Get type of the image by regexp for extension. Returns undefined for unknown extensions.

Name Type Description
url string

the image path

Returns:
Type Description
string | undefined image extension

PIXI.utils.hex2rgb (hex, out)Array.<number> static

Converts a hex color number to an [R, G, B] array

Name Type Default Description
hex number

The number to convert

out Array.<number> [] optional

If supplied, this array will be used rather than returning a new one

Returns:
Type Description
Array.<number> An array representing the [R, G, B] of the color.

PIXI.utils.hex2string (hex)string static

Converts a hex color number to a string.

Name Type Description
hex number

Number in hex

Returns:
Type Description
string The string color.

PIXI.utils.isMobile ()Object static

See:
Returns:
Type Description
Object

PIXI.utils.isWebGLSupported ()boolean static

Helper for checking for webgl support

Returns:
Type Description
boolean is webgl supported

PIXI.utils.pluginTarget ()mixin static

Returns:
Type Description
mixin

PIXI.utils.removeItems ()Object static

See:
Returns:
Type Description
Object

PIXI.utils.rgb2hex (rgb)number static

Converts a color as an [R, G, B] array to a hex number

Name Type Description
rgb Array.<number>

rgb array

Returns:
Type Description
number The color number

PIXI.utils.sayHello (type) static

Logs out the version and renderer information for this running instance of PIXI. If you don't want to see this message you can run PIXI.utils.skipHello() before creating your renderer. Keep in mind that doing that will forever makes you a jerk face.

Name Type Description
type string

The string renderer type to log.

PIXI.utils.sign (n)number static

Returns sign of number

Name Type Description
n number

the number to check the sign of

Returns:
Type Description
number 0 if n is 0, -1 if n is negative, 1 if n is positive

PIXI.utils.skipHello () static

Skips the hello message of renderers that are created after this is run.

PIXI.utils.uid ()number static

Gets the next unique identifier

Returns:
Type Description
number The next unique identifier to use.

PIXI.utils.uuid ()number Deprecated : since version 3.0.6 static

See:
Returns:
Type Description
number The uid

Type Definitions

DecomposedDataUri object

Typedef for decomposeDataUri return object.

Properties:
Name Type Description
Media mediaType

type, eg. image

Sub subType

type, eg. png

Data encoding

encoding, eg. base64

The data

actual data

Size object

Typedef for Size object.

Properties:
Name Type Description
Width width

component

Height height

component