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 (options)

Name Type Description
options object optional
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 PIXI.SCALE_MODES optional

See PIXI.SCALE_MODES for possible values

resolution number 1 optional

The resolution / device pixel ratio of the texture being generated

Extends

Members

cacheId string inherited

Currently default cache ID.

destroyed boolean readonly inherited

Flag if BaseTexture has been destroyed.

filterStack Array.<PIXI.Graphics>

The data structure for the filters

The pixel format of the texture

Default Value:
  • PIXI.FORMATS.RGBA

height number readonly inherited overrides

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

isPowerOfTwo boolean readonly inherited

Whether or not the texture is a power of two, try to use power of two textures as much as you can

Default Value:
  • false

mipmap boolean inherited overrides

If mipmapping was used for this texture, enable and disable with enableMipmap()

premultiplyAlpha boolean inherited

Set to true to enable pre-multiplied alpha

Default Value:
  • true

realHeight number readonly inherited

Pixel height of the source of this texture

realWidth number readonly inherited

Pixel width of the source of this texture

resolution number inherited

The resolution / device pixel ratio of the texture

Default Value:
  • PIXI.settings.RESOLUTION

The resource used by this BaseTexture, there can only be one resource per BaseTexture, but textures can share resources.

scaleMode number inherited

The scale mode to apply when scaling this texture

Default Value:
  • PIXI.settings.SCALE_MODE
See:

stencilMaskStack Array.<PIXI.Graphics>

The data structure for the stencil masks

The target type

Default Value:
  • PIXI.TARGETS.TEXTURE_2D

textureCacheIds Array.<string> readonly inherited

The collection of alternative cache ids, since some BaseTextures can have more than one ID, short name and longer full URL

The type of resource data

Default Value:
  • PIXI.TYPES.UNSIGNED_BYTE

valid boolean readonly inherited overrides

Generally speaking means when resource is loaded.

width number readonly inherited overrides

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

wrapMode number inherited

How the texture wraps

Methods

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:
  • PIXI.BaseTexture#event:dispose

getDrawableSource ()CanvasImageSource inherited

Get the drawable source, such as HTMLCanvasElement or HTMLImageElement suitable for rendering with CanvasRenderer. Provided by @pixi/canvas-renderer package.

Returns:
Type Description
CanvasImageSource Source to render with CanvasRenderer

resize (width, height)

Resizes the BaseRenderTexture.

Name Type Description
width number

The width to resize to.

height number

The height to resize to.

setRealSize (realWidth, realHeight, resolution)BaseTexture inherited

Sets real size of baseTexture, preserves current resolution.

Name Type Description
realWidth number

Full rendered width

realHeight number

Full rendered height

resolution number optional

Optionally set resolution

Returns:
Type Description
BaseTexture this

setResolution (resolution)BaseTexture inherited

Changes resolution

Name Type Description
resolution number optional

res

Returns:
Type Description
BaseTexture this

setResource (resource)BaseTexture inherited

Sets the resource if it wasnt set. Throws error if resource already present

Name Type Description
resource PIXI.resources.Resource

that is managing this BaseTexture

Returns:
Type Description
BaseTexture this

setSize (width, height, resolution)BaseTexture inherited

Changes w/h/resolution. Texture becomes valid if width and height are greater than zero.

Name Type Description
width number

Visual width

height number

Visual height

resolution number optional

Optionally set resolution

Returns:
Type Description
BaseTexture this

setStyle (options, scaleMode, mipmap)BaseTexture inherited

Changes style options of BaseTexture

Name Type Description
options object
scaleMode PIXI.SCALE_MODES optional

pixi scalemode

mipmap boolean optional

enable mipmaps

Returns:
Type Description
BaseTexture this

Invalidates the object. Texture becomes valid if width and height are greater than zero.