PIXI.utils

namespace utils

Generalized convenience utilities for PIXI.


 // 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"

Summary


Properties from utils

object
static BaseTextureCache
object
static ProgramCache
object
static TextureCache
object
isMobile
object
path
Array<number<Array>>
premultiplyBlendMode
object
url

Public Properties


BaseTextureCache caches.ts:21
static BaseTextureCache: object
ProgramCache caches.ts:3
static ProgramCache: object
TextureCache caches.ts:12
static TextureCache: object
isMobile index.ts:20
isMobile: object

A simple JS library that detects mobile devices.

Properties:
Name Type Description
amazon object
amazon boolean

.device - true if any Silk device

amazon boolean

.tablet - true if any Silk tablet

amazon boolean

.phone - true if any Silk phone

android object
android boolean

.device - true if any Android device

android boolean

.tablet - true if any Android tablet

android boolean

.phone - true if any Android phone

any boolean

true if current platform is tablet or phone device

apple object
apple boolean

.device - true if any Apple device

apple boolean

.tablet - true if any Apple iPad

apple boolean

.phone - true if any Apple iPhone

apple boolean

.ipod - true if any iPod

phone boolean

true if current platform small-screen phone device

tablet boolean

true if current platform large-screen tablet device

windows object
windows boolean

.device - true if any Windows device

windows boolean

.tablet - true if any Windows tablet

windows boolean

.phone - true if any Windows phone

See: https://github.com/kaimallea/isMobile
path index.ts:79
path: object

Browser and Node.js compatible path utilities. All paths that are passed in will become normalized to have posix separators.

premultiplyBlendMode premultiply.ts:37
premultiplyBlendMode: Array<number<Array>>

maps premultiply flag and blendMode to adjusted blendMode

url index.ts:71
url: object

Node.js compatible URL utilities.

See: https://www.npmjs.com/package/url

Public Methods


earcut index.ts:59
earcut(vertices: Array<number>, holes: Array<number>, dimensions: number) → {Array<number>}

A polygon triangulation library

Parameters:
Name Type Attributes Default Description
vertices Array<number>

A flat array of vertex coordinates

holes Array<number>

<optional>

An array of hole indices

dimensions number

<optional>

2

The number of coordinates per vertex in the input array

Returns:
Type Description
Array<number>

Triangulated polygon

See: https://github.com/mapbox/earcut
sayHello hello.ts:16
sayHello(type: string) → {void}

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 make you a jerk face.

Parameters:
Name Type Description
type string

The string renderer type to log.

Returns:
Type Description
void
clearTextureCache caches.ts:49
clearTextureCache() → {void}

Removes all textures from cache, but does not destroy them

Returns:
Type Description
void
correctBlendMode premultiply.ts:45
correctBlendMode(blendMode: number, premultiplied: boolean) → {number}

changes blendMode according to texture format

Parameters:
Name Type Description
blendMode number

supposed blend mode

premultiplied boolean

whether source is premultiplied

Returns:
Type Description
number

true blend mode for this texture

createIndicesForQuads createIndicesForQuads.ts:1
createIndicesForQuads(size: number, outBuffer: Uint16Array | Uint32Array) → {Uint16Array | Uint32Array}

Generic Mask Stack data structure

Parameters:
Name Type Attributes Default Description
size number

Number of quads

outBuffer Uint16Array | Uint32Array

<optional>

undefined

Buffer for output, length has to be 6 * size

Returns:
Type Description
Uint16Array | Uint32Array
  • Resulting index buffer
decomposeDataUri decomposeDataUri.ts:46
decomposeDataUri(dataUri: string) → {PIXI.utils.DecomposedDataUri | unknown}

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

Parameters:
Name Type Description
dataUri string

the data URI to check

Returns:
Type Description
PIXI.utils.DecomposedDataUri | unknown

The decomposed data uri or undefined

deprecation deprecation.ts:6
deprecation(version: string, message: string, ignoreDepth: number) → {void}

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.

Parameters:
Name Type Attributes 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

<optional>

3

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

Returns:
Type Description
void
destroyTextureCache caches.ts:30
destroyTextureCache() → {void}

Destroys all texture in the cache

Returns:
Type Description
void
getResolutionOfUrl getResolutionOfUrl.ts:3
getResolutionOfUrl(url: string, defaultValue: number) → {number}

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

Parameters:
Name Type Attributes Default Description
url string

the image path

defaultValue number

<optional>

1

the defaultValue if no filename prefix is set.

Returns:
Type Description
number

resolution / device pixel ratio of an asset

hex2rgb hex.ts:3
hex2rgb(hex: number, out: Array<number>) → {Array<number>}

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


 PIXI.utils.hex2rgb(0xffffff); // returns [1, 1, 1]
Parameters:
Name Type Attributes 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.

hex2string hex.ts:22
hex2string(hex: number) → {string}

Converts a hexadecimal color number to a string.


 PIXI.utils.hex2string(0xffffff); // returns "#ffffff"
Parameters:
Name Type Description
hex number

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

Returns:
Type Description
string

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

isPow2 pow2.ts:23
isPow2(v: number) → {boolean}

Checks if a number is a power of two.

Parameters:
Name Type Description
v number

input value

Returns:
Type Description
boolean

true if value is power of two

isWebGLSupported isWebGLSupported.ts:5
isWebGLSupported() → {boolean}

Helper for checking for WebGL support.

Returns:
Type Description
boolean

Is WebGL supported.

log2 pow2.ts:35
log2(v: number) → {number}

Computes ceil of log base 2

Parameters:
Name Type Description
v number

input value

Returns:
Type Description
number

logarithm base 2

nextPow2 pow2.ts:3
nextPow2(v: number) → {number}

Rounds to next power of two.

Parameters:
Name Type Description
v number

input value

Returns:
Type Description
number
  • next rounded power of two
premultiplyRgba premultiply.ts:58
premultiplyRgba(rgb: Float32Array | number<Array>, alpha: number, out: Float32Array, premultiply: boolean) → {Float32Array}

combines rgb and alpha to out array

Parameters:
Name Type Attributes Default Description
rgb Float32Array | number<Array>

input rgb

alpha number

alpha param

out Float32Array

<optional>

output

premultiply boolean

<optional>

true

do premultiply it

Returns:
Type Description
Float32Array

vec4 rgba

premultiplyTint premultiply.ts:93
premultiplyTint(tint: number, alpha: number) → {number}

premultiplies tint

Parameters:
Name Type Description
tint number

integer RGB

alpha number

floating point alpha (0.0-1.0)

Returns:
Type Description
number

tint multiplied by alpha

premultiplyTintToRgba premultiply.ts:122
premultiplyTintToRgba(tint: number, alpha: number, out: Float32Array, premultiply: boolean) → {Float32Array}

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

Parameters:
Name Type Attributes Default Description
tint number

input tint

alpha number

alpha param

out Float32Array

<optional>

output

premultiply boolean

<optional>

true

do premultiply it

Returns:
Type Description
Float32Array

vec4 rgba

removeItems removeItems.ts:1
removeItems(arr: Array, startIdx: number, removeCount: number) → {void}

Remove items from a javascript array without generating garbage

Parameters:
Name Type Description
arr Array<any>

Array to remove elements from

startIdx number

starting index

removeCount number

how many to remove

Returns:
Type Description
void
rgb2hex hex.ts:69
rgb2hex(rgb: Array<number>) → {number}

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


 PIXI.utils.rgb2hex([1, 1, 1]); // returns 0xffffff
Parameters:
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.

sign sign.ts:1
sign(n: number) → {number}

Returns sign of number

Parameters:
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

skipHello hello.ts:6
skipHello() → {void}

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

Returns:
Type Description
void
string2hex hex.ts:40
string2hex(string: string) → {number}

Converts a string to a hexadecimal color number. It can handle: hex strings starting with #: "#ffffff" hex strings starting with 0x: "0xffffff" hex strings without prefix: "ffffff" css colors: "black"


 PIXI.utils.string2hex("#ffffff"); // returns 0xffffff
Parameters:
Name Type Description
string string

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

Returns:
Type Description
number

Number in hexadecimal.

trimCanvas trimCanvas.ts:9
trimCanvas(canvas: HTMLCanvasElement) → {object}

Trim transparent borders from a canvas

Parameters:
Name Type Description
canvas HTMLCanvasElement

the canvas to trim

Returns:
Type Description
object

Trim data

uid uid.ts:3
uid() → {number}

Gets the next unique identifier

Returns:
Type Description
number

The next unique identifier to use.


Powered by webdoc!