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.
{cc.Sprite} clearFlags
- Code for "auto" update.
{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-255
    {Number} g
    green 0-255
    {Number} b
    blue 0-255
    {Number} a
    alpha 0-255 0 is transparent
    {Number} depthValue Optional
    {Number} stencilValue Optional
  • cleanup()
    Clear RenderTexture.
  • 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
  • clearRect(x, y, width, height)
    clears the texture with rect.
    Parameters:
    {number} x
    {number} y
    {number} width
    {number} height
  • 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
    Parameters:
    {Number} width
    {Number} height
    {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} format
    {Number} depthStencilFormat
    Deprecated:
    since v3.0 please use new cc.RenderTexture() instead.
    Returns:
    {cc.RenderTexture}
  • ctor(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 Constructor of cc.RenderTexture for Canvas
    // Example
    var rt = new cc.RenderTexture(width, height, format, depthStencilFormat)
    Parameters:
    {Number} width
    {Number} height
    {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} format
    {Number} depthStencilFormat
  • 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()
    Gets the sprite
    Returns:
    {cc.Sprite}
  • {Boolean} initWithWidthAndHeight(width, height, format, depthStencilFormat)
    Initializes the instance of cc.RenderTexture
    Parameters:
    {Number} width
    {Number} height
    {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} format Optional
    {Number} depthStencilFormat Optional
    Returns:
    {Boolean}
  • {Boolean} isAutoDraw()
    When enabled, it will render its children into the texture automatically. Disabled by default for compatibility 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
  • {Boolean} setAutoDraw(autoDraw)
    When enabled, it will render its children into the texture automatically. Disabled by default for compatibility reasons.
    Will be enabled in the future.
    Parameters:
    autoDraw
    Returns:
    {Boolean}
  • setClearColor(clearColor)
    Set the clear color value. Valid only when "autoDraw" is true.
    Parameters:
    {cc.Color} clearColor
    The clear color
  • setClearDepth(clearDepth)
    Set value for clearDepth. Valid only when autoDraw is true.
    Parameters:
    {Number} clearDepth
  • setClearFlags(clearFlags)
    Set the clearFlags
    Parameters:
    {Number} clearFlags
  • {Number} setClearStencil(clearStencil)
    Set value for clear Stencil. Valid only when autoDraw is true
    Parameters:
    clearStencil
    Returns:
    {Number}
  • setSprite(sprite)
    Set the sprite
    Parameters:
    {cc.Sprite} sprite
  • setVirtualViewport(rtBegin, fullRect, fullViewport)
    Used for grab part of screen to a texture.
    Parameters:
    {cc.Point} rtBegin
    {cc.Rect} fullRect
    {cc.Rect} fullViewport