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

CanvasRenderTarget
EventEmitter

Namespaces

mixins

Members

PIXI.utils.BaseTextureCache Object static

TODO
  • Describe property usage

PIXI.utils.isMobile Object static

A simple JS library that detects mobile devices.

Properties:
Name Type Description
any boolean

true if current platform is tablet or phone device

tablet boolean

true if current platform large-screen tablet device

phone boolean

true if current platform small-screen phone device

apple object
Properties
Name Type Description
device boolean

true if any Apple device

tablet boolean

true if any Apple iPad

phone boolean

true if any Apple iPhone

ipod boolean

true if any iPod

android object
Properties
Name Type Description
device boolean

true if any Android device

tablet boolean

true if any Android tablet

phone boolean

true if any Android phone

amazon object
Properties
Name Type Description
device boolean

true if any Silk device

tablet boolean

true if any Silk tablet

phone boolean

true if any Silk phone

windows object
Properties
Name Type Description
device boolean

true if any Windows device

tablet boolean

true if any Windows tablet

phone boolean

true if any Windows phone

See:

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

maps premultiply flag and blendMode to adjusted blendMode

PIXI.utils.ProgramCache Object static

TODO
  • Describe property usage

PIXI.utils.TextureCache Object static

TODO
  • Describe property usage

PIXI.utils.url object static

Node.js compatible URL utilities.

See:

Methods

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.deprecation (version, message, ignoreDepth) static

Helper for warning developers about deprecated features & settings. A stack track for warnings is given; useful for tracking-down where deprecated methods/properties/classes are being used within the code.

Name Type Default Description
version string

The version where the feature became deprecated

message string

Message should include what is deprecated, where, and the new solution

ignoreDepth number 3 optional

The number of steps to ignore at the top of the error stack this is mostly to ignore internal deprecation calls.

PIXI.utils.destroyTextureCache () static

Destroys all texture in the cache

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

A polygon triangulation library

Name Type Default Description
vertices Array.<number>

A flat array of vertex coordinates

holes Array.<number> optional

An array of hole indices

dimensions number 2 optional

The number of coordinates per vertex in the input array

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

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 () Deprecated : since 5.0.0 static

See:

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

Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0).

Name Type Default Description
hex number

The hexadecimal 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 where all values are floats.
Example
PIXI.utils.hex2rgb(0xffffff); // returns [1, 1, 1]

PIXI.utils.hex2string (hex)string static

Converts a hexadecimal color number to a string.

Name Type Description
hex number

Number in hex (e.g., 0xffffff)

Returns:
Type Description
string The string color (e.g., "#ffffff").
Example
PIXI.utils.hex2string(0xffffff); // returns "#ffffff"

PIXI.utils.isPow2 (v)boolean static

Checks if a number is a power of two.

Name Type Description
v number

input value

Returns:
Type Description
boolean true if value is power of two

PIXI.utils.isPow2 (v)number static

Rounds to next power of two.

Name Type Description
v number

input value

Returns:
Type Description
number

PIXI.utils.isWebGLSupported ()boolean static

Helper for checking for WebGL support.

Returns:
Type Description
boolean Is WebGL supported.

PIXI.utils.log2 (v)number static

Computes ceil of log base 2

Name Type Description
v number

input value

Returns:
Type Description
number logarithm base 2

PIXI.utils.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.premultiplyTint (tint, alpha)number static

premultiplies tint

Name Type Description
tint number

integer RGB

alpha number

floating point alpha (0.0-1.0)

Returns:
Type Description
number tint multiplied by alpha

PIXI.utils.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.removeItems (arr, startIdx, removeCount) static

Remove items from a javascript array without generating garbage

Name Type Description
arr Array.<any>

Array to remove elements from

startIdx number

starting index

removeCount number

how many to remove

PIXI.utils.rgb2hex (rgb)number static

Converts a color as an [R, G, B] array of normalized floats to a hexadecimal number.

Name Type Description
rgb Array.<number>

Array of numbers where all values are normalized floats from 0.0 to 1.0.

Returns:
Type Description
number Number in hexadecimal.
Example
PIXI.utils.rgb2hex([1, 1, 1]); // returns 0xffffff

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.string2hex (The)number static

Converts a hexadecimal string to a hexadecimal color number.

Name Type Description
The string

string color (e.g., "#ffffff")

Returns:
Type Description
number Number in hexadecimal.
Example
PIXI.utils.string2hex("#ffffff"); // returns 0xffffff

PIXI.utils.trimCanvas (canvas)object static

Trim transparent borders from a canvas

Name Type Description
canvas HTMLCanvasElement

the canvas to trim

Returns:
Type Description
object Trim data

PIXI.utils.uid ()number static

Gets the next unique identifier

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

Type Definitions

PIXI.utils.DecomposedDataUri object

Typedef for decomposeDataUri return object.

Properties:
Name Type Description
mediaType string

Media type, eg. image

subType string

Sub type, eg. png

encoding string

Data encoding, eg. base64

data string

The actual data