#

API Docs for: 2.0.0
Show: Inherited Protected Private Deprecated

# Texture Class

Uses

- EventTarget

Defined in: `src/pixi/textures/Texture.js:10`
Module: PIXI

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]`

)

Defined in `src/pixi/textures/Texture.js:10`

#### 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

- Index
- Methods
- Properties

## Item Index

### Methods

- _updateUvs
- addTextureToCache static
- destroy
- emit
- fromCanvas static
- fromFrame static
- fromImage static
- listeners
- mixin
- off
- on
- onBaseTextureLoaded
- once
- removeAllListeners
- removeTextureFromCache static
- setFrame

### Properties

- _uvs
- baseTexture
- crop
- frame
- height
- noFrame
- requiresUpdate
- trim
- valid
- width

## Methods

### `_updateUvs`

() private

Defined in `src/pixi/textures/Texture.js:200`

Updates the internal WebGL UV cache.

### `addTextureToCache`

(

- `texture`
- `id`

)
static

Defined in `src/pixi/textures/Texture.js:284`

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`

)

Defined in `src/pixi/textures/Texture.js:149`

Destroys this texture

#### Parameters:

- `destroyBase` Boolean

  Whether to destroy the base texture as well

### `emit`

(

- `eventName`

)
Boolean

Inherited from EventTarget: `src/pixi/utils/EventTarget.js:54`

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

Defined in `src/pixi/textures/Texture.js:267`

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

Defined in `src/pixi/textures/Texture.js:251`

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

Defined in `src/pixi/textures/Texture.js:227`

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

Inherited from EventTarget: `src/pixi/utils/EventTarget.js:41`

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`

)

Inherited from EventTarget: `src/pixi/utils/EventTarget.js:34`

Mixes in the properties of the EventTarget prototype onto another object

#### Parameters:

- `object` Object

  The obj to mix into

### `off`

(

- `eventName`
- `callback`

)

Inherited from EventTarget: `src/pixi/utils/EventTarget.js:143`

Remove event listeners.

#### Parameters:

- `eventName` String

  The event we want to remove.

- `callback` Function

  The listener that we need to find.

### `on`

(

- `eventName`
- `callback`

)

Inherited from EventTarget: `src/pixi/utils/EventTarget.js:107`

Register a new EventListener for the given event.

#### Parameters:

- `eventName` String

  Name of the event.

- `callback` Functon

  fn Callback function.

### `onBaseTextureLoaded`

() private

Defined in `src/pixi/textures/Texture.js:131`

Called when the base texture is loaded

### `once`

(

- `eventName`
- `callback`

)

Inherited from EventTarget: `src/pixi/utils/EventTarget.js:124`

Add an EventListener that's only called once.

#### Parameters:

- `eventName` String

  Name of the event.

- `callback` Function

  Callback function.

### `removeAllListeners`

(

- `eventName`

)

Inherited from EventTarget: `src/pixi/utils/EventTarget.js:173`

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

Defined in `src/pixi/textures/Texture.js:297`

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`

)

Defined in `src/pixi/textures/Texture.js:162`

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

Defined in `src/pixi/textures/Texture.js:83`

The WebGL UV data cache.

### `baseTexture`

BaseTexture

Defined in `src/pixi/textures/Texture.js:43`

The base texture that this texture uses.

### `crop`

Rectangle

Defined in `src/pixi/textures/Texture.js:108`

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

Defined in `src/pixi/textures/Texture.js:51`

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

### `height`

Number

Defined in `src/pixi/textures/Texture.js:100`

The height of the Texture in pixels.

### `noFrame`

Boolean

Defined in `src/pixi/textures/Texture.js:24`

Does this Texture have any frame data assigned to it?

### `requiresUpdate`

Boolean

Defined in `src/pixi/textures/Texture.js:75`

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

### `trim`

Rectangle

Defined in `src/pixi/textures/Texture.js:59`

The texture trim data.

### `valid`

Boolean

Defined in `src/pixi/textures/Texture.js:67`

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

### `width`

Number

Defined in `src/pixi/textures/Texture.js:92`

The width of the Texture in pixels.