Class: RenderTexture

PIXI. 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:

let renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 });
let renderTexture = PIXI.RenderTexture.create(800, 600);
let 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;

renderer.render(sprite, renderTexture);

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

let doc = new PIXI.Container();

doc.addChild(sprite);

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

new PIXI.RenderTexture(baseRenderTexture, frame)

Name Type Description
baseRenderTexture PIXI.BaseRenderTexture

The renderer used for this RenderTexture

frame PIXI.Rectangle optional

The rectangle frame of the texture to show

Extends

Members

frame

Set the frame.

heightnumber

The height of the Texture in pixels.

rotatenumber

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

widthnumber

The width of the Texture in pixels.

Methods

staticPIXI.RenderTexture.create(width, height, scaleMode, resolution){PIXI.RenderTexture}

A short hand way of creating a render texture.

Name Type Default Description
width number 100 optional

The width of the render texture

height number 100 optional

The height of the render texture

scaleMode number PIXI.SCALE_MODES.DEFAULT optional

See PIXI.SCALE_MODES for possible values

resolution number 1 optional

The resolution / device pixel ratio of the texture being generated

Returns:
Type Description
PIXI.RenderTexture The new render texture

Updates the internal WebGL UV cache.

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

Returns:
Type Description
PIXI.Texture The new texture

Destroys this texture

Name Type Default Description
destroyBase boolean false optional

Whether to destroy the base texture as well

resize(width, height, doNotResizeBaseTexture)

Resizes the RenderTexture.

Name Type Description
width number

The width to resize to.

height number

The height to resize to.

doNotResizeBaseTexture boolean

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

inherited setFrame(frame)

Name Type Description
frame PIXI.Rectangle

The frame to set.

Deprecated
  • since version 3.0.0
    See:

    Updates this texture on the gpu.

    Events

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