| Package | starling.textures |
| Class | public class RenderTexture |
| Inheritance | RenderTexture Texture Object |
After creating a render texture, just call the drawObject method to render
an object directly onto the texture. The object will be drawn onto the texture at its current
position, adhering its current rotation, scale and alpha properties.
Drawing is done very efficiently, as it is happening directly in graphics memory. After you have drawn objects onto the texture, the performance will be just like that of a normal texture - no matter how many objects you have drawn.
If you draw lots of objects at once, it is recommended to bundle the drawing calls in
a block via the drawBundled method, like shown below. That will speed it up
immensely, allowing you to draw hundreds of objects very quickly.
renderTexture.drawBundled(function():void
{
for (var i:int=0; i<numDrawings; ++i)
{
image.rotation = (2 * Math.PI / numDrawings) * i;
renderTexture.draw(image);
}
});
To erase parts of a render texture, you can use any display object like a "rubber" by setting its blending mode to "BlendMode.ERASE".
Beware that render textures can't be restored when the Starling's render context is lost.
| Property | Defined By | ||
|---|---|---|---|
| base : TextureBase [override] [read-only] The Stage3D texture object the texture is based on. | RenderTexture | ||
![]() | frame : Rectangle [read-only] The texture frame (see class description). | Texture | |
| height : Number [override] [read-only] The height of the texture in pixels. | RenderTexture | ||
| isPersistent : Boolean [read-only] Indicates if the texture is persistent over multiple draw calls. | RenderTexture | ||
![]() | mipMapping : Boolean [read-only] Indicates if the texture contains mip maps. | Texture | |
| premultipliedAlpha : Boolean [override] [read-only] Indicates if the alpha values are premultiplied into the RGB values. | RenderTexture | ||
![]() | repeat : Boolean Indicates if the texture should repeat like a wallpaper or stretch the outermost pixels. | Texture | |
| scale : Number [override] [read-only] The scale factor, which influences width and height properties. | RenderTexture | ||
| width : Number [override] [read-only] The width of the texture in pixels. | RenderTexture | ||
| Method | Defined By | ||
|---|---|---|---|
RenderTexture(width:int, height:int, persistent:Boolean = true, scale:Number = -1) Creates a new RenderTexture with a certain size. | RenderTexture | ||
adjustVertexData(vertexData:VertexData, vertexID:int, count:int):void [override] Converts texture coordinates and vertex positions of raw vertex data into the format
required for rendering. | RenderTexture | ||
clear():void Clears the texture (restoring full transparency). | RenderTexture | ||
dispose():void [override] Disposes the underlying texture data. | RenderTexture | ||
draw(object:DisplayObject, antiAliasing:int = 0):void Draws an object onto the texture, adhering its properties for position, scale, rotation
and alpha. | RenderTexture | ||
drawBundled(drawingBlock:Function, antiAliasing:int = 0):void Bundles several calls to draw together in a block. | RenderTexture | ||
![]() | empty(width:int = 64, height:int = 64, color:uint = 0xffffffff, optimizeForRenderTexture:Boolean = false, scale:Number = -1):Texture [static] Creates an empty texture of a certain size and color. | Texture | |
![]() | fromAtfData(data:ByteArray, scale:Number = 1):Texture [static] Creates a texture from the compressed ATF format. | Texture | |
![]() | fromBitmap(data:Bitmap, generateMipMaps:Boolean = true, optimizeForRenderTexture:Boolean = false, scale:Number = 1):Texture [static] Creates a texture object from a bitmap. | Texture | |
![]() | fromBitmapData(data:BitmapData, generateMipMaps:Boolean = true, optimizeForRenderTexture:Boolean = false, scale:Number = 1):Texture [static] Creates a texture from bitmap data. | Texture | |
![]() | [static] Creates a texture that contains a region (in pixels) of another texture. | Texture | |
![]() | uploadAtfData(nativeTexture:Texture, data:ByteArray, offset:int = 0):void [static] Uploads ATF data from a ByteArray to a native texture. | Texture | |
![]() | uploadBitmapData(nativeTexture:Texture, data:BitmapData, generateMipmaps:Boolean):void [static] Uploads the bitmap data to the native texture, optionally creating mipmaps. | Texture | |
| base | property |
base:TextureBase [read-only] [override] The Stage3D texture object the texture is based on.
public function get base():TextureBase| height | property |
height:Number [read-only] [override] The height of the texture in pixels.
public function get height():Number| isPersistent | property |
isPersistent:Boolean [read-only] Indicates if the texture is persistent over multiple draw calls.
public function get isPersistent():Boolean| premultipliedAlpha | property |
premultipliedAlpha:Boolean [read-only] [override] Indicates if the alpha values are premultiplied into the RGB values.
public function get premultipliedAlpha():Boolean| scale | property |
scale:Number [read-only] [override] The scale factor, which influences width and height properties.
public function get scale():Number| width | property |
width:Number [read-only] [override] The width of the texture in pixels.
public function get width():Number| RenderTexture | () | Constructor |
public function RenderTexture(width:int, height:int, persistent:Boolean = true, scale:Number = -1)Creates a new RenderTexture with a certain size. If the texture is persistent, the contents of the texture remains intact after each draw call, allowing you to use the texture just like a canvas. If it is not, it will be cleared before each draw call. Persistancy doubles the required graphics memory! Thus, if you need the texture only for one draw (or drawBundled) call, you should deactivate it.
Parameterswidth:int | |
height:int | |
persistent:Boolean (default = true) | |
scale:Number (default = -1) |
| adjustVertexData | () | method |
override public function adjustVertexData(vertexData:VertexData, vertexID:int, count:int):voidConverts texture coordinates and vertex positions of raw vertex data into the format required for rendering.
Parameters
vertexData:VertexData | |
vertexID:int | |
count:int |
| clear | () | method |
public function clear():voidClears the texture (restoring full transparency).
| dispose | () | method |
override public function dispose():voidDisposes the underlying texture data.
| draw | () | method |
public function draw(object:DisplayObject, antiAliasing:int = 0):voidDraws an object onto the texture, adhering its properties for position, scale, rotation and alpha.
Parameters
object:DisplayObject | |
antiAliasing:int (default = 0) |
| drawBundled | () | method |
public function drawBundled(drawingBlock:Function, antiAliasing:int = 0):void Bundles several calls to draw together in a block. This avoids buffer
switches and allows you to draw multiple objects into a non-persistent texture.
Parameters
drawingBlock:Function | |
antiAliasing:int (default = 0) |