Class: RenderTexture

RenderTexture

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 renderer = autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 });
var renderTexture = new RenderTexture(renderer, 800, 600);
var sprite = 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 Node should be used:

var doc = new Node();

doc.addChild(sprite);

renderTexture.render(doc);  // Renders to center of renderTexture

new RenderTexture(renderer [, width] [, height] [, scaleMode] [, resolution])

Parameters:
Name Type Argument Default Description
renderer CanvasRenderer | WebGLRenderer

The renderer used for this RenderTexture

width number <optional>
100

The width of the render texture

height number <optional>
100

The height of the render texture

scaleMode number <optional>

See SCALE_MODES for possible values

resolution number <optional>
1

The resolution of the texture being generated

Source:

Extends

Members


baseTexture :BaseTexture

The base texture that this texture uses.

Type:
Inherited From:
Source:

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)

Type:
Inherited From:
Source:

frame :Rectangle

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

Type:
Inherited From:
Source:

height :number

The height of the render texture

Type:
  • number
Overrides:
Source:

noFrame :boolean

Does this Texture have any frame data assigned to it?

Type:
  • boolean
Inherited From:
Source:

renderer :CanvasRenderer|WebGLRenderer

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

Type:
Source:

requiresUpdate :boolean

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

Type:
  • boolean
Inherited From:
Source:

resolution :number

The Resolution of the texture.

Type:
  • number
Source:

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 GroupD8 for explanation

Type:
  • number
Inherited From:
Source:

trim :Rectangle

The texture trim data.

Type:
Inherited From:
Source:

valid :boolean

Type:
  • boolean
Overrides:
Source:

width :number

The with of the render texture

Type:
  • number
Overrides:
Source:

Methods


clear()

Clears the RenderTexture.

Source:

destroy(destroyBase)

Destroys this texture

Parameters:
Name Type Description
destroyBase boolean

Whether to destroy the base texture as well

Source:

getBase64()

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

Source:
Returns:

A base64 encoded string of the texture.

Type
string

getCanvas()

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

Source:
Returns:

A Canvas element with the texture rendered on.

Type
HTMLCanvasElement

getImage()

Will return a HTML Image of the texture

Source:
Returns:
Type
Image

getPixel(x, y)

Will return a one-dimensional array containing the pixel data of a pixel within the texture in RGBA order, with integer values between 0 and 255 (included).

Parameters:
Name Type Description
x number

The x coordinate of the pixel to retrieve.

y number

The y coordinate of the pixel to retrieve.

Source:
Returns:
Type
Uint8ClampedArray

getPixels()

Will return a one-dimensional array containing the pixel data of the entire texture in RGBA order, with integer values between 0 and 255 (included).

Source:
Returns:
Type
Uint8ClampedArray

render(displayObject [, matrix] [, clear] [, updateTransform])

Draw/render the given DisplayObject onto the texture.

The displayObject and descendents are transformed during this operation.
If updateTransform is true then the transformations will be restored before the
method returns. Otherwise it is up to the calling code to correctly use or reset
the transformed display objects.

The display object is always rendered with a worldAlpha value of 1.

Parameters:
Name Type Argument Default Description
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>
false

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

updateTransform boolean <optional>
true

If true the displayObject's worldTransform/worldAlpha and all children
transformations will be restored. Not restoring this information will be a little faster.

Source:

resize(width, height, updateBase)

Resizes the RenderTexture.

Parameters:
Name Type Description
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?

Source:

Events


update

Fired when the texture is updated. This happens if the frame or the baseTexture is updated.

Inherited From:
Source: