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

{Boolean} autoDraw
- Indicate auto draw mode activate or not.
{cc.Color} clearColorVal
- Clear color value, valid only when "autoDraw" is true.
{Number} clearDepthVal
- Clear depth value.
clearFlags

Code for "auto" update
Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
They can be OR'ed. Valid when "autoDraw is YES.

{Number} clearStencilVal
- Clear stencil value.
{cc.Sprite} sprite
- The sprite.

Method Detail

  • begin()
    starts grabbing
  • 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
  • clearDepth(depthValue)
    clears the texture with a specified depth value
    Parameters:
    {Number} depthValue
  • clearStencil(stencilValue)
    clears the texture with a specified stencil value
    Parameters:
    {Number} stencilValue
  • <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}
  • end()
    ends grabbing
  • {cc.Color} getClearColor()
    Clear color value. Valid only when "autoDraw" is true.
    Returns:
    {cc.Color}
  • {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} initWithWidthAndHeight(width, height, format, depthStencilFormat)
    Parameters:
    {Number} width
    {Number} height
    {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} format
    {Number} depthStencilFormat
    Returns:
    {Boolean}
  • {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
  • {*} newCCImage(flipImage)
    creates a new CCImage from with the texture's data. Caller is responsible for releasing it by calling delete.
    Parameters:
    flipImage
    Returns:
    {*}
  • 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
  • setClearColor(clearColor)
    Set the clear color value. Valid only when "autoDraw" is true.
    Parameters:
    {cc.Color} clearColor
    The clear color
  • setSprite(sprite)
    Parameters:
    {cc.Sprite} sprite