RenderTexture Class
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 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);
The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual position a DisplayObjectContainer should be used:
var doc = new PIXI.DisplayObjectContainer(); doc.addChild(sprite); renderTexture.render(doc); // Renders to center of renderTexture
Constructor
RenderTexture
-
[width]
-
[height]
-
[renderer]
-
[scaleMode]
-
[resolution]
Parameters:
-
[width]
Float optionalThe width of the render texture
-
[height]
Float optionalThe height of the render texture
-
[renderer]
CanvasRenderer | WebGLRenderer optionalThe renderer used for this RenderTexture
-
[scaleMode]
Int optionalShould be one of the PIXI.scaleMode consts
-
[resolution]
Float optionalThe resolution of the texture being generated
Item Index
Methods
Properties
Methods
clear
()
Clears the RenderTexture.
destroy
-
destroyBase
Destroys this texture
Parameters:
-
destroyBase
BoolWhether to destroy the base texture as well
emit
-
eventName
-
data
Emit an event to all registered event listeners.
Parameters:
-
eventName
StringThe name of the event.
-
data
Dynamic
Returns:
Indication if we've emitted an event.
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:
A base64 encoded string of the texture.
getCanvas
()
CanvasElement
Creates a Canvas element, renders this RenderTexture to it and then returns it.
Returns:
A Canvas element with the texture rendered on.
getImage
()
HTMLImage
Will return a HTML Image of the texture
Returns:
listeners
-
eventName
Return a list of assigned event listeners.
Parameters:
-
eventName
StringThe events that should be listed.
Returns:
An array of listener functions
off
-
eventName
-
callback
Remove event listeners.
on
-
eventName
-
callback
Register a new EventListener for the given event.
Parameters:
-
eventName
StringName of the event.
-
callback
FunctonCallback function.
once
-
eventName
-
callback
Add an EventListener that's only called once.
removeAllListeners
-
eventName
Remove all listeners or only the listeners for the specified event.
Parameters:
-
eventName
StringThe event you want to remove all listeners for.
renderWebGL/renderCanvas
-
displayObject
-
[matrix]
-
[clear]
This function will draw the display object to the texture.
Parameters:
-
displayObject
DisplayObjectThe display object to render this texture on
-
[matrix]
Matrix optionalOptional matrix to apply to the display object before rendering.
-
[clear]
Bool optionalIf true the texture will be cleared before the displayObject is drawn
resize
-
width
-
height
-
[updateBase]
Resize the RenderTexture.
Parameters:
-
width
FloatThe width to resize to.
-
height
FloatThe height to resize to.
-
[updateBase]
Bool optionalShould 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
RectangleThe frame of the texture to set it to
Properties
renderer
CanvasRenderer | WebGLRenderer
The renderer this RenderTexture uses. A RenderTexture can only belong to one renderer at the moment if its webGL.