new PIXI.RenderTexture(renderer, width, height, scaleMode, resolution)
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 = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 });
var renderTexture = new PIXI.RenderTexture(renderer, 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 Container should be used:
var doc = new PIXI.Container();
doc.addChild(sprite);
renderTexture.render(doc); // Renders to center of renderTexture
Name | Type | Default | Description |
---|---|---|---|
renderer |
PIXI.CanvasRenderer | PIXI.WebGLRenderer |
The renderer used for this RenderTexture |
|
width |
number | 100 |
optional
The width of the render texture |
height |
number | 100 |
optional
The height of the render texture |
scaleMode |
number |
optional
See PIXI.SCALE_MODES for possible values |
|
resolution |
number | 1 |
optional
The resolution of the texture being generated |
Extends
Members
-
baseTexturePIXI.BaseTexture
-
The base texture that this texture uses.
-
cropPIXI.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) -
framePIXI.Rectangle
-
The frame specifies the region of the base texture that this texture uses.
-
heightnumber
-
The height of the render texture
-
noFrameboolean
-
Does this Texture have any frame data assigned to it?
-
The renderer this RenderTexture uses. A RenderTexture can only belong to one renderer at the moment if its webGL.
-
requiresUpdateboolean
-
This will let a renderer know that a texture has been updated (used mainly for webGL uv updates)
-
resolutionnumber
-
The Resolution of the texture.
-
trimPIXI.Rectangle
-
The texture trim data.
-
validboolean
-
-
widthnumber
-
The with of the render texture
-
innerbaseTextureBaseTexture
-
The base texture object that this texture uses
Methods
-
clear()
-
Clears the RenderTexture.
-
Creates a new texture object that acts the same as this one.
Returns:
Type Description PIXI.Texture -
destroy(destroyBase)
-
Destroys this texture
Name Type Description destroyBase
boolean Whether to destroy the base texture as well
-
getBase64(){string}
-
Will return a a base64 encoded string of this texture. It works by calling RenderTexture.getCanvas and then running toDataURL on that.
Returns:
Type Description string A base64 encoded string of the texture. -
getCanvas(){HTMLCanvasElement}
-
Creates a Canvas element, renders this RenderTexture to it and then returns it.
Returns:
Type Description HTMLCanvasElement A Canvas element with the texture rendered on. -
getImage(){Image}
-
Will return a HTML Image of the texture
Returns:
Type Description Image -
getPixel(x, y){Uint8ClampedArray}
-
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).
Name Type Description x
number The x coordinate of the pixel to retrieve.
y
number The y coordinate of the pixel to retrieve.
Returns:
Type Description Uint8ClampedArray -
getPixels(){Uint8ClampedArray}
-
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).
Returns:
Type Description Uint8ClampedArray -
render(displayObject, matrix, clear, updateTransform)
-
Draw/render the given DisplayObject onto the texture.
The displayObject and descendents are transformed during this operation.
IfupdateTransform
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.
Name Type Default Description displayObject
PIXI.DisplayObject The display object to render this texture on
matrix
PIXI.Matrix optional Optional matrix to apply to the display object before rendering.
clear
boolean false optional If true the texture will be cleared before the displayObject is drawn
updateTransform
boolean true optional If true the displayObject's worldTransform/worldAlpha and all children
transformations will be restored. Not restoring this information will be a little faster. -
resize(width, height, updateBase)
-
Resizes the RenderTexture.
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?
-
inherited setFrame()
-
- Deprecated
- since version 3.0.0
- See:
-
inherited update()
-
Updates this texture on the gpu.