API Docs for: 2.0.0
Show:

Texture Class

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 PIXI.Sprite. If no frame is provided then the whole image is used.

Constructor

Texture

(
  • baseTexture
  • frame
  • [crop]
  • [trim]
)

Parameters:

  • baseTexture BaseTexture

    The base texture source to create the texture from

  • frame Rectangle

    The rectangle frame of the texture to show

  • [crop] Rectangle optional

    The area of original texture

  • [trim] Rectangle optional

    Trimmed texture rectangle

Methods

_updateUvs

() private

Updates the internal WebGL UV cache.

addTextureToCache

(
  • texture
  • id
)
static

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

Parameters:

  • texture Texture

    The Texture to add to the cache.

  • id String

    The id that the texture will be stored against.

destroy

(
  • destroyBase
)

Destroys this texture

Parameters:

  • destroyBase Boolean

    Whether to destroy the base texture as well

emit

(
  • eventName
)
Boolean

Emit an event to all registered event listeners.

Parameters:

  • eventName String

    The name of the event.

Returns:

Boolean:

Indication if we've emitted an event.

fromCanvas

(
  • canvas
  • scaleMode
)
static

Helper function that creates a new a Texture based on the given canvas element.

Parameters:

  • canvas Canvas

    The canvas element source of the texture

  • scaleMode Number

    Should be one of the PIXI.scaleMode consts

Returns:

Texture

fromFrame

(
  • frameId
)
static

Helper function that returns a Texture objected based on the given frame id. If the frame id is not in the texture cache an error will be thrown.

Parameters:

  • frameId String

    The frame id of the texture

Returns:

Texture

fromImage

(
  • imageUrl
  • crossorigin
  • scaleMode
)
static

Helper function that creates a Texture object from the given image url. If the image is not in the texture cache it will be created and loaded.

Parameters:

  • imageUrl String

    The image url of the texture

  • crossorigin Boolean

    Whether requests should be treated as crossorigin

  • scaleMode Number

    Should be one of the PIXI.scaleMode consts

Returns:

Texture

listeners

(
  • eventName
)
Array

Return a list of assigned event listeners.

Parameters:

  • eventName String

    The events that should be listed.

Returns:

Array:

An array of listener functions

mixin

(
  • object
)

Mixes in the properties of the EventTarget prototype onto another object

Parameters:

  • object Object

    The obj to mix into

off

(
  • eventName
  • callback
)

Remove event listeners.

Parameters:

  • eventName String

    The event we want to remove.

  • callback Function

    The listener that we need to find.

on

(
  • eventName
  • callback
)

Register a new EventListener for the given event.

Parameters:

  • eventName String

    Name of the event.

  • callback Functon

    fn Callback function.

onBaseTextureLoaded

() private

Called when the base texture is loaded

once

(
  • eventName
  • callback
)

Add an EventListener that's only called once.

Parameters:

  • eventName String

    Name of the event.

  • callback Function

    Callback function.

removeAllListeners

(
  • eventName
)

Remove all listeners or only the listeners for the specified event.

Parameters:

  • eventName String

    The event you want to remove all listeners for.

removeTextureFromCache

(
  • id
)
Texture static

Remove a texture from the global PIXI.TextureCache.

Parameters:

  • id String

    The id of the texture to be removed

Returns:

Texture:

The texture that was removed

setFrame

(
  • frame
)

Specifies the region of the baseTexture that this texture will use.

Parameters:

  • frame Rectangle

    The frame of the texture to set it to

Properties

_uvs

Object private

The WebGL UV data cache.

baseTexture

BaseTexture

The base texture that this texture uses.

crop

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)

frame

Rectangle

The frame specifies the region of the base texture that this texture uses

height

Number

The height of the Texture in pixels.

noFrame

Boolean

Does this Texture have any frame data assigned to it?

requiresUpdate

Boolean

This will let a renderer know that a texture has been updated (used mainly for webGL uv updates)

trim

Rectangle

The texture trim data.

valid

Boolean

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

width

Number

The width of the Texture in pixels.