Class cc.RenderTexture

Class Summary
Constructor Attributes Constructor Name and Description
 
cc.RenderTexture is a generic rendering target.

Method Summary

Class Detail

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

Field Detail

begin
starts grabbing
clearDepth
clears the texture with a specified depth value
clearStencil
clears the texture with a specified stencil value
ctor
Constructor
end
ends grabbing
{Boolean} initWithWidthAndHeight
{cc.Image} newCCImage
creates a new CCImage from with the texture's data. Caller is responsible for releasing it by calling delete.

Method Detail

  • beginWithClear(r, g, b, a, depthValue, stencilValue)
    starts rendering to the texture while clearing the texture first.
    This is more efficient then calling -clear first and then -begin
    Parameters:
    {Number} r
    red 0-1
    {Number} g
    green 0-1
    {Number} b
    blue 0-1
    {Number} a
    alpha 0-1 0 is transparent
    {Number} depthValue Optional
    {Number} stencilValue Optional
  • clear(r, g, b, a)
    clears the texture with a color
    Parameters:
    {Number|cc.Rect} r
    red 0-1
    {Number} g
    green 0-1
    {Number} b
    blue 0-1
    {Number} a
    alpha 0-1
  • <static> {cc.RenderTexture} cc.RenderTexture.create(width, height, format, depthStencilFormat)
    creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid
    // Example
    var rt = cc.RenderTexture.create()
    Parameters:
    {Number} width
    {Number} height
    {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} format
    {Number} depthStencilFormat
    Returns:
    {cc.RenderTexture}
  • {cc.Color4F} getClearColor()
    Clear color value. Valid only when "autoDraw" is true.
    Returns:
    {cc.Color4F}
  • {Number} getClearDepth()
    Value for clearDepth. Valid only when autoDraw is true.
    Returns:
    {Number}
  • {Number} getClearFlags()
    Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT. They can be OR'ed. Valid when "autoDraw is YES.
    Returns:
    {Number}
  • {Number} getClearStencil()
    Value for clear Stencil. Valid only when autoDraw is true
    Returns:
    {Number}
  • {cc.Sprite} getSprite()
    The sprite
    Returns:
    {cc.Sprite}
  • {Boolean} isAutoDraw()
    When enabled, it will render its children into the texture automatically. Disabled by default for compatiblity reasons.
    Will be enabled in the future.
    Returns:
    {Boolean}
  • listenToBackground(obj)
    Listen "come to background" message, and save render texture. It only has effect on Android.
    Parameters:
    {cc.Class} obj
  • listenToForeground(obj)
    Listen "come to foreground" message and restore the frame buffer object. It only has effect on Android.
    Parameters:
    {cc.Class} obj
  • saveToFile(filePath, format)
    saves the texture into a file using JPEG format. The file will be saved in the Documents folder. Returns YES if the operation is successful. (doesn't support in HTML5)
    Parameters:
    {Number} filePath
    {Number} format
  • setSprite(sprite)
    Parameters:
    {cc.Sprite} sprite