Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

memberof

PIXI

Type parameters

Hierarchy

Index

Constructors

constructor

Properties

_frame

_frame: Rectangle

Protected _rotate

_rotate: number

_updateID

_updateID: number

_uvs

baseTexture

defaultAnchor

defaultAnchor: Point

noFrame

noFrame: boolean

orig

orig: Rectangle

Optional patternCache

patternCache: {}

Type declaration

  • [key: string]: CanvasPattern

textureCacheIds

textureCacheIds: string[]

Optional tintCache

tintCache: {}

Type declaration

  • [key: string]: HTMLCanvasElement | HTMLImageElement

trim

trim: Rectangle

uvMatrix

uvMatrix: TextureMatrix

valid

valid: boolean

Static Readonly EMPTY

Static Readonly WHITE

Static prefixed

prefixed: string | boolean

Accessors

frame

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

    member

    {PIXI.Rectangle}

    Returns Rectangle

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

    Parameters

    Returns void

height

  • get height(): number
  • The height of the Texture in pixels.

    member

    {number}

    Returns number

resolution

  • get resolution(): number
  • Returns resolution of baseTexture

    member

    {number}

    readonly

    Returns number

rotate

  • get rotate(): number
  • set rotate(rotate: number): void
  • 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

    member

    {number}

    Returns 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

    Parameters

    • rotate: number

    Returns void

width

  • get width(): number
  • The width of the Texture in pixels.

    member

    {number}

    Returns number

Methods

addListener

castToBaseTexture

clone

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

    Returns Texture<Resource>

    The new texture

destroy

  • destroy(destroyBase?: boolean): void
  • Destroys this texture

    Parameters

    • Optional destroyBase: boolean

    Returns void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Return an array listing the events for which the emitter has registered listeners.

    Returns (string | symbol)[]

listenerCount

  • listenerCount(event: string | symbol): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

    Returns number

listeners

  • Return the listeners registered for a given event.

    Parameters

    • event: string | symbol

    Returns ListenerFn[]

off

  • off(event: string | symbol, fn?: ListenerFn, context?: any, once?: boolean): Texture<R>
  • Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns Texture<R>

on

  • Add a listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns Texture<R>

Protected onBaseTextureUpdated

  • Called when the base texture is updated

    Parameters

    Returns void

once

  • Add a one-time listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns Texture<R>

removeAllListeners

  • removeAllListeners(event?: string | symbol): Texture<R>
  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: string | symbol

    Returns Texture<R>

removeListener

  • removeListener(event: string | symbol, fn?: ListenerFn, context?: any, once?: boolean): Texture<R>
  • Remove the listeners of a given event.

    Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns Texture<R>

update

  • update(): void
  • Updates this texture on the gpu.

    Calls the TextureResource update.

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

    Returns void

updateUvs

  • 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 void

Static addToCache

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

    static

    Parameters

    • texture: Texture<Resource>

      The Texture to add to the cache.

    • id: string

      The id that the Texture will be stored against.

    Returns void

Static from

  • 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

    static

    Type parameters

    Parameters

    Returns Texture<R>

    The newly created texture

Static fromBuffer

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

    static

    Parameters

    • 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

    • Optional options: IBaseTextureOptions<ISize>

    Returns Texture<BufferResource>

    The resulting new BaseTexture

Static fromLoader

  • fromLoader<R>(source: string | HTMLCanvasElement | HTMLImageElement, imageUrl: string, name?: string, options?: IBaseTextureOptions<any>): Promise<Texture<R>>
  • Create a texture from a source and add to the cache.

    static

    Type parameters

    Parameters

    • source: string | HTMLCanvasElement | HTMLImageElement

      The input source.

    • imageUrl: string

      File name of texture, for cache and resolving resolution.

    • Optional name: string
    • Optional options: IBaseTextureOptions<any>

    Returns Promise<Texture<R>>

    Output texture

Static fromURL

  • 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.

    Type parameters

    Parameters

    Returns Promise<Texture<R>>

    A Promise that resolves to a Texture.

Static removeFromCache

  • Remove a Texture from the global TextureCache.

    static

    Parameters

    • texture: string | Texture<Resource>

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

    Returns null | Texture<Resource>

    The Texture that was removed

Generated using TypeDoc