SPRenderTexture Class Reference
Inherits from | SPTexture : NSObject |
Declared in | SPRenderTexture.h |
Overview
An SPRenderTexture is a dynamic texture on which you can draw any display 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 on 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 bundleDrawCalls:
method, like shown below. That will speed it up immensely, allowing
you to draw hundreds of objects very quickly.
[renderTexture bundleDrawCalls:^
{
for (int i=0; i<numDrawings; ++i)
{
image.rotation = (2 * PI / numDrawings) * i;
[renderTexture drawObject:image];
}
}];
One thing you should be aware of is that calling any of this class' drawing methods from within
a render:
method of an SPDisplayObject
may lead to problems with texture bindings. To
circumvent this, either move your drawing code into an enter frame event listener or call the
reset
method of SPRenderSupport
after the drawing calls.
Tasks
Initializers
-
– initWithWidth:height:
Initializes a transparent render texture with the scale factor of the stage.
-
– initWithWidth:height:fillColor:
Initializes a render texture with a certain ARGB color (0xAARRGGBB).
-
– initWithWidth:height:fillColor:scale:
Initializes a render texture with a certain ARGB color (0xAARRGGBB) and a scale factor.
-
+ textureWithWidth:height:
Factory method.
-
+ textureWithWidth:height:fillColor:
Factory method.
Methods
-
– drawObject:
Draws an object onto the texture, adhering its properties for position, scale, rotation and alpha.
-
– bundleDrawCalls:
Bundles several calls to
drawObject:
together in a block. This avoids framebuffer switches. -
– clearWithColor:alpha:
Clears the texture with a certain color and alpha value.
Class Methods
Instance Methods
bundleDrawCalls:
Bundles several calls to drawObject:
together in a block. This avoids framebuffer switches.
- (void)bundleDrawCalls:(SPDrawingBlock)block
Discussion
Bundles several calls to drawObject:
together in a block. This avoids framebuffer switches.
Declared In
SPRenderTexture.h
clearWithColor:alpha:
Clears the texture with a certain color and alpha value.
- (void)clearWithColor:(uint)color alpha:(float)alpha
Discussion
Clears the texture with a certain color and alpha value.
Declared In
SPRenderTexture.h
drawObject:
Draws an object onto the texture, adhering its properties for position, scale, rotation and alpha.
- (void)drawObject:(SPDisplayObject *)object
Discussion
Draws an object onto the texture, adhering its properties for position, scale, rotation and alpha.
Declared In
SPRenderTexture.h
initWithWidth:height:
Initializes a transparent render texture with the scale factor of the stage.
- (id)initWithWidth:(float)width height:(float)height
Discussion
Initializes a transparent render texture with the scale factor of the stage.
Declared In
SPRenderTexture.h
initWithWidth:height:fillColor:
Initializes a render texture with a certain ARGB color (0xAARRGGBB).
- (id)initWithWidth:(float)width height:(float)height fillColor:(uint)argb
Discussion
Initializes a render texture with a certain ARGB color (0xAARRGGBB).
Declared In
SPRenderTexture.h
initWithWidth:height:fillColor:scale:
Initializes a render texture with a certain ARGB color (0xAARRGGBB) and a scale factor.
- (id)initWithWidth:(float)width height:(float)height fillColor:(uint)argb scale:(float)scale
Discussion
Initializes a render texture with a certain ARGB color (0xAARRGGBB) and a scale factor.
Declared In
SPRenderTexture.h