API Docs for: 2.0.0
Show:

RenderTexture Class

Extends Texture
Module: PIXI

A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it.

Hint: All DisplayObjects (exmpl. Sprites) that render on RenderTexture should be preloaded. Otherwise black rectangles will be drawn instead.

RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example:

var renderTexture = new PIXI.RenderTexture(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);

Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used:

var doc = new PIXI.DisplayObjectContainer(); doc.addChild(sprite); renderTexture.render(doc); // Renders to center of renderTexture

Constructor

RenderTexture

(
  • width
  • height
  • scaleMode
  • resolution
)

Parameters:

  • width Number

    The width of the render texture

  • height Number

    The height of the render texture

  • scaleMode Number

    Should be one of the PIXI.scaleMode consts

  • resolution Number

    The resolution of the texture being generated

Methods

_updateWebGLuvs

() private

Updates the internal WebGL UV cache.

clear

()

Clears the RenderTexture.

destroy

(
  • destroyBase
)

Destroys this texture

Parameters:

  • destroyBase Boolean

    Whether to destroy the base texture as well

emit

(
  • eventName
)
Boolean

Emit an event to all registered event listeners.

Parameters:

  • eventName String

    The name of the event.

Returns:

Boolean:

Indication if we've emitted an event.

getImage

()

Will return a HTML Image of the texture

getImage

()

Will return a a base64 string of the texture

listeners

(
  • eventName
)
Array

Return a list of assigned event listeners.

Parameters:

  • eventName String

    The events that should be listed.

Returns:

Array:

An array of listener functions

mixin

(
  • object
)

Mixes in the properties of the EventTarget prototype onto another object

Parameters:

  • object Object

    The obj to mix into

off

(
  • eventName
  • callback
)

Remove event listeners.

Parameters:

  • eventName String

    The event we want to remove.

  • callback Function

    The listener that we need to find.

on

(
  • eventName
  • callback
)

Register a new EventListener for the given event.

Parameters:

  • eventName String

    Name of the event.

  • callback Functon

    fn Callback function.

onBaseTextureLoaded

(
  • event
)
private

Called when the base texture is loaded

Parameters:

  • event Object

once

(
  • eventName
  • callback
)

Add an EventListener that's only called once.

Parameters:

  • eventName String

    Name of the event.

  • callback Function

    Callback function.

removeAllListeners

(
  • eventName
)

Remove all listeners or only the listeners for the specified event.

Parameters:

  • eventName String

    The event you want to remove all listeners for.

renderCanvas

(
  • displayObject
  • clear
)
private

This function will draw the display object to the texture.

Parameters:

  • displayObject DisplayObject

    The display object to render this texture on

  • clear Boolean

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

renderWebGL

(
  • displayObject
  • clear
)
private

This function will draw the display object to the texture.

Parameters:

  • displayObject DisplayObject

    The display object to render this texture on

  • clear Boolean

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

resize

(
  • width
  • height
  • updateBase
)

Resize the RenderTexture.

Parameters:

  • 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?

setFrame

(
  • frame
)

Specifies the region of the baseTexture that this texture will use.

Parameters:

  • frame Rectangle

    The frame of the texture to set it to

Properties

_uvs

Object private

The WebGL UV data cache.

baseTexture

BaseTexture

Inherited from Texture but overwritten in src/pixi/textures/RenderTexture.js:78

The base texture object that this texture uses

crop

Rectangle

Inherited from Texture but overwritten in src/pixi/textures/RenderTexture.js:69

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)

frame

Rectangle

Inherited from Texture but overwritten in src/pixi/textures/RenderTexture.js:61

The framing rectangle of the render texture

height

Number

Inherited from Texture but overwritten in src/pixi/textures/RenderTexture.js:45

The height of the render texture

noFrame

Boolean

Does this Texture have any frame data assigned to it?

requiresUpdate

Boolean

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

resolution

Number

The Resolution of the texture.

trim

Rectangle

The trim point

valid

Boolean

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

width

Number

Inherited from Texture but overwritten in src/pixi/textures/RenderTexture.js:37

The with of the render texture