Inherits from CCNode : CCResponder : NSObject
Declared in CCRenderTexture.h

Overview

CCRenderTexture is a generic rendering target. To render things into it, simply construct a render target, call begin on it, call visit on any cocos2d scenes or objects to render them, and call end. For convenience, render texture adds a sprite as its display child with the results, so you can simply add the render texture to your scene and treat it like any other CCNode. There are also functions for saving the render texture to disk in PNG or JPG format.

Properties

autoDraw

When enabled, it will render its children into the texture automatically. Disabled by default for compatiblity reasons. Will be enabled in the future.

@property (nonatomic, readwrite) BOOL autoDraw

Declared In

CCRenderTexture.h

clearColor

Clear color value. Valid only when “autoDraw” is YES.

@property (nonatomic, strong) CCColor *clearColor

Declared In

CCRenderTexture.h

clearDepth

Value for clearDepth. Valid only when autoDraw is YES.

@property (nonatomic, readwrite) GLclampf clearDepth

Declared In

CCRenderTexture.h

clearFlags

Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT. They can be OR'ed. Valid when “autoDraw is YES.

@property (nonatomic, readwrite) GLbitfield clearFlags

Declared In

CCRenderTexture.h

clearStencil

Value for clear Stencil. Valid only when autoDraw is YES

@property (nonatomic, readwrite) GLint clearStencil

Declared In

CCRenderTexture.h

sprite

The CCSprite that is used for rendering. A subtle change introduced in v3.1.1 is that this sprite is rendered explicitly and is not a child of the render texture.

@property (nonatomic, readwrite, strong) CCSprite *sprite

Declared In

CCRenderTexture.h

Class Methods

renderTextureWithWidth:height:

Creates a RenderTexture object with width and height in Points, pixel format is RGBA8888

+ (id)renderTextureWithWidth:(int)w height:(int)h

Parameters

w

Width of render target.

h

Height of render target.

Return Value

An initialized CCRenderTarget object.

Declared In

CCRenderTexture.h

renderTextureWithWidth:height:pixelFormat:

Creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid

+ (id)renderTextureWithWidth:(int)w height:(int)h pixelFormat:(CCTexturePixelFormat)format

Parameters

w

Width of render target.

h

Height of render target.

format

Pixel format of render target.

Return Value

An initialized CCRenderTarget object.

Declared In

CCRenderTexture.h

renderTextureWithWidth:height:pixelFormat:depthStencilFormat:

initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format

+ (id)renderTextureWithWidth:(int)w height:(int)h pixelFormat:(CCTexturePixelFormat)format depthStencilFormat:(GLuint)depthStencilFormat

Parameters

w

Width of render target.

h

Height of render target.

format

Pixel format of render target.

depthStencilFormat

Stencil format of render target.

Return Value

An initialized CCRenderTarget object.

Declared In

CCRenderTexture.h

Instance Methods

begin

Starts rendering to the texture whitout clearing the texture first.

- (void)begin

Declared In

CCRenderTexture.h

beginWithClear:g:b:a:

starts rendering to the texture while clearing the texture first. This is more efficient then calling -clear first and then begin.

- (void)beginWithClear:(float)r g:(float)g b:(float)b a:(float)a

Parameters

r

Red color.

g

Green color.

b

Blue color.

a

Alpha.

Declared In

CCRenderTexture.h

beginWithClear:g:b:a:depth:

starts rendering to the texture while clearing the texture first. This is more efficient then calling -clear first and then begin.

- (void)beginWithClear:(float)r g:(float)g b:(float)b a:(float)a depth:(float)depthValue

Parameters

r

Red color.

g

Green color.

b

Blue color.

a

Alpha.

depthValue

Depth value.

Declared In

CCRenderTexture.h

beginWithClear:g:b:a:depth:stencil:

starts rendering to the texture while clearing the texture first. This is more efficient then calling -clear first and then begin.

- (void)beginWithClear:(float)r g:(float)g b:(float)b a:(float)a depth:(float)depthValue stencil:(int)stencilValue

Parameters

r

Red color.

g

Green color.

b

Blue color.

a

Alpha.

depthValue

Depth value.

stencilValue

Stencil value.

Declared In

CCRenderTexture.h

clear:g:b:a:

Clears the texture with a color

- (void)clear:(float)r g:(float)g b:(float)b a:(float)a

Parameters

r

Red color.

g

Green color.

b

Blue color.

a

Alpha.

Declared In

CCRenderTexture.h

clearDepth:

Clears the texture with a specified depth value.

- (void)clearDepth:(float)depthValue

Parameters

depthValue

Depth value.

Declared In

CCRenderTexture.h

clearStencil:

Clears the texture with a specified stencil value.

- (void)clearStencil:(int)stencilValue

Parameters

stencilValue

Stencil value.

Declared In

CCRenderTexture.h

end

Ends grabbing

- (void)end

Declared In

CCRenderTexture.h

getUIImage

Returns an autoreleased UIImage from the texture

- (UIImage *)getUIImage

Declared In

CCRenderTexture.h

initWithWidth:height:pixelFormat:

Initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid

- (id)initWithWidth:(int)w height:(int)h pixelFormat:(CCTexturePixelFormat)format

Parameters

w

Width of render target.

h

Height of render target.

format

Pixel format of render target.

Return Value

An initialized CCRenderTarget object.

Declared In

CCRenderTexture.h

initWithWidth:height:pixelFormat:depthStencilFormat:

Initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format

- (id)initWithWidth:(int)w height:(int)h pixelFormat:(CCTexturePixelFormat)format depthStencilFormat:(GLuint)depthStencilFormat

Parameters

w

Width of render target.

h

Height of render target.

format

Pixel format of render target.

depthStencilFormat

Stencil format of render target.

Return Value

An initialized CCRenderTarget object.

Declared In

CCRenderTexture.h

saveToFile:

Saves the texture into a file using JPEG format. The file will be saved in the Documents folder.

- (BOOL)saveToFile:(NSString *)name

Parameters

name

Filename to save image to.

Return Value

YES if the operation is successful.

Declared In

CCRenderTexture.h

saveToFile:format:

Saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder.

- (BOOL)saveToFile:(NSString *)name format:(CCRenderTextureImageFormat)format

Parameters

name

Filename to save image to.

format

File format.

Return Value

YES if the operation is successful.

Declared In

CCRenderTexture.h

saveToFilePath:

Saves the texture into a file using JPEG format.

- (BOOL)saveToFilePath:(NSString *)filePath

Parameters

filePath

File path to save image to.

Return Value

YES if the operation was successful.

Declared In

CCRenderTexture.h

saveToFilePath:format:

Saves the texture into a file. The format could be JPG or PNG.

- (BOOL)saveToFilePath:(NSString *)filePath format:(CCRenderTextureImageFormat)format

Parameters

filePath

File path to save image to.

format

File format.

Return Value

YES if the operation was successful.

Declared In

CCRenderTexture.h