Class: BaseRenderTexture

PIXI.BaseRenderTexture

A BaseRenderTexture is a special texture that allows any PixiJS display object to be rendered to it.

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

A BaseRenderTexture 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 baseRenderTexture = new PIXI.BaseRenderTexture(renderer, 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;

baseRenderTexture.render(sprite);

The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0 you can clear the transform


sprite.setTransform()

let baseRenderTexture = new PIXI.BaseRenderTexture(100, 100);
let renderTexture = new PIXI.RenderTexture(baseRenderTexture);

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

new PIXI.BaseRenderTexture (width, height, scaleMode, resolution)

Name Type Default Description
width number 100 optional

The width of the base render texture

height number 100 optional

The height of the base render texture

scaleMode number PIXI.settings.SCALE_MODE optional

See PIXI.SCALE_MODES for possible values

resolution number 1 optional

The resolution / device pixel ratio of the texture being generated

Extends

Members

hasLoaded boolean readonly inherited

Set to true once the base texture has successfully loaded.

This is never true if the underlying source fails to load or has no texture data.

height number readonly inherited overrides

The height of the base texture set when the image has loaded

imageType string readonly inherited

Type of image defined in source, eg. png or svg

imageUrl string inherited

The image url of the texture

isLoading boolean readonly inherited

Set to true if the source is currently loading.

If an Image source is loading the 'loaded' or 'error' event will be dispatched when the operation ends. An underyling source that is immediately-available bypasses loading entirely.

mipmap boolean inherited

Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used Also the texture must be a power of two size to work

See:

origSource Image readonly inherited

The image source that is used to create the texture. This is used to store the original Svg source when it is replaced with a canvas element.

TODO: Currently not in use but could be used when re-scaling svg.

premultipliedAlpha boolean inherited

Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) All blend modes, and shaders written for default value. Change it on your own risk.

Default Value:
  • true

realHeight number readonly inherited overrides

Used to store the actual height of the source of this texture

realWidth number readonly inherited overrides

Used to store the actual width of the source of this texture

resolution number inherited

The resolution / device pixel ratio of the texture

Default Value:
  • 1

scaleMode number inherited

The scale mode to apply when scaling this texture

Default Value:
  • PIXI.settings.SCALE_MODE
See:

source HTMLImageElement | HTMLCanvasElement readonly inherited

The image source that is used to create the texture.

TODO: Make this a setter that calls loadSource();

sourceScale number readonly inherited

Scale for source image. Used with Svg images to scale them before rasterization.

textureCacheIds Array.<string> inherited

The ids under which this BaseTexture has been added to the base texture cache. This is automatically set as long as BaseTexture.addToCache is used, but may not be set if a BaseTexture is added directly to the BaseTextureCache array.

valid boolean

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

width number readonly inherited overrides

The width of the base texture set when the image has loaded

wrapMode number inherited

WebGL Texture wrap mode

See:

Methods

_loadSvgSource () inherited

Checks if source is an SVG image and whether it's loaded via a URL or a data URI. Then calls _loadSvgSourceUsingDataUri or _loadSvgSourceUsingXhr.

_loadSvgSourceUsingDataUri (dataUri) inherited

Reads an SVG string from data URI and then calls _loadSvgSourceUsingString.

Name Type Description
dataUri string

The data uri to load from.

_loadSvgSourceUsingString (svgString) inherited

Loads texture using an SVG string. The original SVG Image is stored as origSource and the created canvas is the new source. The SVG is scaled using sourceScale. Called by _loadSvgSourceUsingXhr or _loadSvgSourceUsingDataUri.

Name Type Description
svgString string

SVG source as string

Fires:

_loadSvgSourceUsingXhr () inherited

Loads an SVG string from imageUrl using XHR and then calls _loadSvgSourceUsingString.

_updateDimensions () inherited

Update dimensions from real values

_updateImageType () inherited

Updates type of the source image.

Destroys this texture

Frees the texture from WebGL memory without destroying this texture object. This means you can still use the texture later which will upload it to GPU memory again.

Fires:

loadSource (source) protected inherited

Load a source.

If the source is not-immediately-available, such as an image that needs to be downloaded, then the 'loaded' or 'error' event will be dispatched in the future and hasLoaded will remain false after this call.

The logic state after calling loadSource directly or indirectly (eg. fromImage, new BaseTexture) is:

if (texture.hasLoaded) {
   // texture ready for use
} else if (texture.isLoading) {
   // listen to 'loaded' and/or 'error' events on texture
} else {
   // not loading, not going to load UNLESS the source is reloaded
   // (it may still make sense to listen to the events)
}
Name Type Description
source HTMLImageElement | HTMLCanvasElement

the source object of the texture.

resize (width, height)

Resizes the BaseRenderTexture.

Name Type Description
width number

The width to resize to.

height number

The height to resize to.

Updates the texture on all the webgl renderers, this also assumes the src has changed.

Fires:

updateSourceImage (newSrc) inherited

Changes the source image of the texture. The original source must be an Image element.

Name Type Description
newSrc string

the path of the image

Events

Fired when BaseTexture is destroyed.

Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being destroyed.

Fired when a not-immediately-available source fails to load.

Name Type Description
baseTexture PIXI.BaseTexture

Resource errored.

Fired when a not-immediately-available source finishes loading.

Name Type Description
baseTexture PIXI.BaseTexture

Resource loaded.

Fired when BaseTexture is updated.

Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being updated.