PIXI.Texture

class Texture extends EventEmitter

A texture stores the information that represents an image or part of an image.

It cannot be added to the display list directly; instead use it as the texture for a Sprite. If no frame is provided for a texture, then the whole image is used.

You can directly create a texture from an image and then reuse it multiple times like this :

let texture = PIXI.Texture.from('assets/image.png');
let sprite1 = new PIXI.Sprite(texture);
let sprite2 = new PIXI.Sprite(texture);

If you didnt pass the texture frame to constructor, it enables noFrame mode: it subscribes on baseTexture events, it automatically resizes at the same time as baseTexture.

Textures made from SVGs, loaded or not, cannot be used before the file finishes processing. You can check for this by checking the sprite's _textureID property.

var texture = PIXI.Texture.from('assets/image.svg');
var sprite1 = new PIXI.Sprite(texture);
//sprite1._textureID should not be undefined if the texture has finished processing the SVG file

You can use a ticker or rAF to ensure your sprites load the finished textures after processing. See issue #3068.

Constructor


new PIXI.Texture(baseTexture: PIXI.BaseTexture<R>, frame: PIXI.Rectangle, orig: PIXI.Rectangle, trim: PIXI.Rectangle, rotate: number, anchor: IPointData) → {}
Parameters:
Name Type Attributes Description
baseTexture PIXI.BaseTexture<R>

The base texture source to create the texture from

frame PIXI.Rectangle

<optional>

The rectangle frame of the texture to show

orig PIXI.Rectangle

<optional>

The area of original texture

trim PIXI.Rectangle

<optional>

Trimmed rectangle of original texture

rotate number

<optional>

indicates how the texture was rotated by texture packer. See PIXI.groupD8

anchor IPointData

<optional>

Default anchor point used for sprite placement / rotation

Summary


Properties from Texture

PIXI.Texture<PIXI.Resource>
static EMPTY

An empty texture, used often to not have to create multiple empty textures. Can not be destroyed.

PIXI.Texture<PIXI.CanvasResource>
static WHITE

A white texture of 16x16 size, used for graphics and other things Can not be destroyed.

PIXI.Rectangle
_frame
PIXI.BaseTexture<R>
baseTexture

The base texture that this texture uses.

PIXI.Point
defaultAnchor = {0,0}
PIXI.Rectangle
frame
number
height

The height of the Texture in pixels.

boolean
noFrame

Does this Texture have any frame data assigned to it?

PIXI.Rectangle
orig

This is the area of original texture, before it was put in atlas.

number
resolution
number
rotate
Array<string>
textureCacheIds
PIXI.Rectangle
trim
PIXI.TextureMatrix
uvMatrix

Default TextureMatrix instance for this texture. By default, that object is not created because its heavy.

boolean
valid

This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.

number
width

The width of the Texture in pixels.

number
protected _updateID
PIXI.TextureUvs
protected _uvs

Public Properties


EMPTY Texture.ts:666
static EMPTY: PIXI.Texture<PIXI.Resource>

An empty texture, used often to not have to create multiple empty textures. Can not be destroyed.

WHITE Texture.ts:679
static WHITE: PIXI.Texture<PIXI.CanvasResource>

A white texture of 16x16 size, used for graphics and other things Can not be destroyed.

_frame Texture.ts:114
_frame: PIXI.Rectangle

This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering, irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases)

baseTexture Texture.ts:63
baseTexture: PIXI.BaseTexture<R>

The base texture that this texture uses.

defaultAnchor Texture.ts:96
defaultAnchor: PIXI.Point = {0,0}

Anchor point that is used as default if sprite is created with this texture. Changing the defaultAnchor at a later point of time will not update Sprite's anchor point.

frame Texture.ts:582
frame: PIXI.Rectangle

The frame specifies the region of the base texture that this texture uses. Please call updateUvs() after you change coordinates of frame manually.

height Texture.ts:651
height: number

The height of the Texture in pixels.

noFrame Texture.ts:78
noFrame: boolean

Does this Texture have any frame data assigned to it?

This mode is enabled automatically if no frame was passed inside constructor.

In this mode texture is subscribed to baseTexture events, and fires update on any change.

Beware, after loading or resize of baseTexture event can fired two times! If you want more control, subscribe on baseTexture itself.

texture.on('update', () => {});

Any assignment of frame switches off noFrame mode.

orig Texture.ts:66
orig: PIXI.Rectangle

This is the area of original texture, before it was put in atlas.

resolution Texture.ts:573
resolution: number

Returns resolution of baseTexture

rotate Texture.ts:624
rotate: number

Indicates whether the texture is rotated inside the atlas set to 2 to compensate for texture packer rotation set to 6 to compensate for spine packer rotation can be used to rotate or mirror sprites See PIXI.groupD8 for explanation

textureCacheIds Texture.ts:126
textureCacheIds: Array<string>

The ids under which this Texture has been added to the texture cache. This is automatically set as long as Texture.addToCache is used, but may not be set if a Texture is added directly to the TextureCache array.

trim Texture.ts:69
trim: PIXI.Rectangle

This is the trimmed area of original texture, before it was put in atlas Please call updateUvs() after you change coordinates of trim manually.

uvMatrix Texture.ts:103
uvMatrix: PIXI.TextureMatrix

Default TextureMatrix instance for this texture. By default, that object is not created because its heavy.

valid Texture.ts:75
valid: boolean

This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.

width Texture.ts:645
width: number

The width of the Texture in pixels.

Protected Properties


_updateID Texture.ts:107
protected _updateID: number

Update ID is observed by sprites and TextureMatrix instances. Call updateUvs() to increment it.

_uvs Texture.ts:120
protected _uvs: PIXI.TextureUvs

The WebGL UV data cache. Can be used as quad UV.

Public Methods


addToCache Texture.ts:505
static addToCache(texture: PIXI.Texture, id: string) → {void}

Adds a Texture to the global TextureCache. This cache is shared across the whole PIXI object.

Parameters:
Name Type Description
texture PIXI.Texture

The Texture to add to the cache.

id string

The id that the Texture will be stored against.

Returns:
Type Description
void
from Texture.ts:331
static from(source: string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | PIXI.BaseTexture, options: IBaseTextureOptions<RO>, strict: boolean) → {PIXI.Texture}

Helper function that creates a new Texture based on the source you provide. The source can be - frame id, image url, video url, canvas element, video element, base texture

Parameters:
Name Type Attributes Default Description
source string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | PIXI.BaseTexture

Source or array of sources to create texture from

options IBaseTextureOptions<RO>

See PIXI.BaseTexture's constructor for options.

options.pixiIdPrefix string

<optional>

pixiid

If a source has no id, this is the prefix of the generated id

strict boolean

<optional>

Enforce strict-mode, see PIXI.settings.STRICT_TEXTURE_CACHE.

Returns:
Type Description
PIXI.Texture

The newly created texture

fromBuffer Texture.ts:433
static fromBuffer(buffer: Float32Array | Uint8Array, width: number, height: number, options: IBaseTextureOptions<ISize>) → {PIXI.Texture<PIXI.BufferResource>}

Create a new Texture with a BufferResource from a Float32Array. RGBA values are floats from 0 to 1.

Parameters:
Name Type Attributes Description
buffer Float32Array | Uint8Array

The optional array to use, if no data is provided, a new Float32Array is created.

width number

Width of the resource

height number

Height of the resource

options IBaseTextureOptions<ISize>

<optional>

See PIXI.BaseTexture's constructor for options.

Returns:
Type Description
PIXI.Texture<PIXI.BufferResource>
  • The resulting new BaseTexture
fromLoader Texture.ts:449
static fromLoader(source: HTMLImageElement | HTMLCanvasElement | string, imageUrl: string, name: string, options: IBaseTextureOptions) → {Promise<R<PIXI.Texture>>}

Create a texture from a source and add to the cache.

Parameters:
Name Type Attributes Description
source HTMLImageElement | HTMLCanvasElement | string

The input source.

imageUrl string

File name of texture, for cache and resolving resolution.

name string

<optional>

Human readable name for the texture cache. If no name is specified, only imageUrl will be used as the cache ID.

options IBaseTextureOptions

<optional>

Returns:
Type Description
Promise<R<PIXI.Texture>>
  • Output texture
fromURL Texture.ts:408
static fromURL(url: string | string[], options: IBaseTextureOptions<RO>) → {Promise<R<PIXI.Texture>>}

Useful for loading textures via URLs. Use instead of Texture.from because it does a better job of handling failed URLs more effectively. This also ignores PIXI.settings.STRICT_TEXTURE_CACHE. Works for Videos, SVGs, Images.

Parameters:
Name Type Attributes Description
url string | string[]

The remote URL or array of URLs to load.

options IBaseTextureOptions<RO>

<optional>

Optional options to include

Returns:
Type Description
Promise<R<PIXI.Texture>>
  • A Promise that resolves to a Texture.
removeFromCache Texture.ts:529
static removeFromCache(texture: string | PIXI.Texture) → {PIXI.Texture | null}

Remove a Texture from the global TextureCache.

Parameters:
Name Type Description
texture string | PIXI.Texture

id of a Texture to be removed, or a Texture instance itself

Returns:
Type Description
PIXI.Texture | null
  • The Texture that was removed
castToBaseTexture Texture.ts:657
castToBaseTexture() → {PIXI.BaseTexture}

Utility function for BaseTexture|Texture cast.

Returns:
Type Description
PIXI.BaseTexture
clone Texture.ts:291
clone() → {PIXI.Texture}

Creates a new texture object that acts the same as this one.

Returns:
Type Description
PIXI.Texture
  • The new texture
destroy Texture.ts:252
destroy(destroyBase: boolean) → {void}

Destroys this texture

Parameters:
Name Type Attributes Default Description
destroyBase boolean

<optional>

false

Whether to destroy the base texture as well

Returns:
Type Description
void
update Texture.ts:208
update() → {void}

Updates this texture on the gpu.

Calls the TextureResource update.

If you adjusted frame manually, please call updateUvs() instead.

Returns:
Type Description
void
updateUvs Texture.ts:315
updateUvs() → {void}

Updates the internal WebGL UV cache. Use it after you change frame or trim of the texture. Call it after changing the frame

Returns:
Type Description
void

Protected Methods


onBaseTextureUpdated Texture.ts:223
protected onBaseTextureUpdated(baseTexture: PIXI.BaseTexture) → {void}

Called when the base texture is updated

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

The base texture.

Returns:
Type Description
void

Powered by webdoc!