#

API Docs for: 2.0.0
Show: Inherited Protected Private Deprecated

# RenderTexture Class

Extends Texture
Defined in: `src/pixi/textures/RenderTexture.js:5`
Module: PIXI

A RenderTexture is a special texture that allows any Pixi display object to be rendered to it.

Hint: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded otherwise black rectangles will be drawn instead.

A RenderTexture takes a snapshot of any Display Object given to its render method. The position and rotation of the given Display Objects is ignored. For example:

var renderTexture = new PIXI.RenderTexture(800, 600); var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); sprite.position.x = 800/2; sprite.position.y = 600/2; sprite.anchor.x = 0.5; sprite.anchor.y = 0.5; renderTexture.render(sprite);

The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual position a DisplayObjectContainer should be used:

var doc = new PIXI.DisplayObjectContainer(); doc.addChild(sprite); renderTexture.render(doc); // Renders to center of renderTexture

## Constructor

### `RenderTexture`

(

- `width`
- `height`
- `renderer`
- `scaleMode`
- `resolution`

)

Defined in `src/pixi/textures/RenderTexture.js:5`

#### Parameters:

- `width` Number

  The width of the render texture

- `height` Number

  The height of the render texture

- `renderer` CanvasRenderer | WebGLRenderer

  The renderer used for this RenderTexture

- `scaleMode` Number

  Should be one of the PIXI.scaleMode consts

- `resolution` Number

  The resolution of the texture being generated

- Index
- Methods
- Properties

## Item Index

### Methods

- _updateUvs
- clear
- destroy
- emit
- getBase64
- getCanvas
- getImage
- listeners
- mixin
- off
- on
- onBaseTextureLoaded
- once
- removeAllListeners
- renderCanvas
- renderWebGL
- resize
- setFrame

### Properties

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

## Methods

### `_updateUvs`

() private

Inherited from Texture: `src/pixi/textures/Texture.js:200`

Updates the internal WebGL UV cache.

### `clear`

()

Defined in `src/pixi/textures/RenderTexture.js:171`

Clears the RenderTexture.

### `destroy`

(

- `destroyBase`

)

Inherited from Texture: `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.

### `getBase64`

() String

Defined in `src/pixi/textures/RenderTexture.js:288`

Will return a a base64 encoded string of this texture. It works by calling RenderTexture.getCanvas and then running toDataURL on that.

#### Returns:

String:

A base64 encoded string of the texture.

### `getCanvas`

() HTMLCanvasElement

Defined in `src/pixi/textures/RenderTexture.js:299`

Creates a Canvas element, renders this RenderTexture to it and then returns it.

#### Returns:

HTMLCanvasElement:

A Canvas element with the texture rendered on.

### `getImage`

() HTMLImage

Defined in `src/pixi/textures/RenderTexture.js:275`

Will return a HTML Image of the texture

#### Returns:

HTMLImage:

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

Inherited from Texture: `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.

### `renderCanvas`

(

- `displayObject`
- `[matrix]`
- `[clear]`

)
private

Defined in `src/pixi/textures/RenderTexture.js:237`

This function will draw the display object to the texture.

#### Parameters:

- `displayObject` DisplayObject

  The display object to render this texture on

- `[matrix]` Matrix optional

  Optional matrix to apply to the display object before rendering.

- `[clear]` Boolean optional

  If true the texture will be cleared before the displayObject is drawn

### `renderWebGL`

(

- `displayObject`
- `[matrix]`
- `[clear]`

)
private

Defined in `src/pixi/textures/RenderTexture.js:188`

This function will draw the display object to the texture.

#### Parameters:

- `displayObject` DisplayObject

  The display object to render this texture on

- `[matrix]` Matrix optional

  Optional matrix to apply to the display object before rendering.

- `[clear]` Boolean optional

  If true the texture will be cleared before the displayObject is drawn

### `resize`

(

- `width`
- `height`
- `updateBase`

)

Defined in `src/pixi/textures/RenderTexture.js:137`

Resizes the RenderTexture.

#### Parameters:

- `width` Number

  The width to resize to.

- `height` Number

  The height to resize to.

- `updateBase` Boolean

  Should the baseTexture.width and height values be resized as well?

### `setFrame`

(

- `frame`

)

Inherited from Texture: `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

Inherited from Texture: `src/pixi/textures/Texture.js:83`

The WebGL UV data cache.

### `baseTexture`

BaseTexture

Inherited from Texture but overwritten in `src/pixi/textures/RenderTexture.js:78`

The base texture object that this texture uses

### `crop`

Rectangle

Inherited from Texture but overwritten in `src/pixi/textures/RenderTexture.js:69`

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

Inherited from Texture but overwritten in `src/pixi/textures/RenderTexture.js:61`

The framing rectangle of the render texture

### `height`

Number

Inherited from Texture but overwritten in `src/pixi/textures/RenderTexture.js:45`

The height of the render texture

### `noFrame`

Boolean

Inherited from Texture: `src/pixi/textures/Texture.js:24`

Does this Texture have any frame data assigned to it?

### `renderer`

CanvasRenderer | WebGLRenderer

Defined in `src/pixi/textures/RenderTexture.js:99`

The renderer this RenderTexture uses. A RenderTexture can only belong to one renderer at the moment if its webGL.

### `requiresUpdate`

Boolean

Inherited from Texture: `src/pixi/textures/Texture.js:75`

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

### `resolution`

Number

Defined in `src/pixi/textures/RenderTexture.js:53`

The Resolution of the texture.

### `trim`

Rectangle

Inherited from Texture: `src/pixi/textures/Texture.js:59`

The texture trim data.

### `valid`

Boolean

Inherited from Texture but overwritten in `src/pixi/textures/RenderTexture.js:125`

### `width`

Number

Inherited from Texture but overwritten in `src/pixi/textures/RenderTexture.js:37`

The with of the render texture