Class cc.Texture2D

Class Summary
Constructor Attributes Constructor Name and Description
 

This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data.

Method Summary

Class Detail

cc.Texture2D()

This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data.
The created cc.Texture2D object will always have power-of-two dimensions.
Depending on how you create the cc.Texture2D object, the actual image area of the texture might be smaller than the texture dimensions
i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0).
Be aware that the content of the generated textures will be upside-down!

Field Detail

{Number} height
- Content height in points
{Number} maxS
- Texture max S
{Number} maxT
- Texture max T
{WebGLTexture} name
- <@readonly> WebGLTexture Object
{Number} pixelFormat
- <@readonly> Pixel format of the texture
{Number} pixelsHeight
- <@readonly> Height in pixels
{Number} pixelsWidth
- <@readonly> Width in pixels
{cc.GLProgram} shaderProgram
- The shader program used by drawAtPoint and drawInRect
{Number} width
- Content width in points

Method Detail

  • addLoadedEventListener(callback, target)
    add listener for loaded event
    Parameters:
    {Function} callback
    {cc.Node} target
    Deprecated:
    since 3.1, please use addEventListener instead
  • {string} description()
    description of cc.Texture2D
    Returns:
    {string}
  • {cc.Size} getContentSize()
    get content size
    Returns:
    {cc.Size}
  • {cc.Size} getContentSizeInPixels()
    get content size in pixels
    Returns:
    {cc.Size}
  • {HTMLImageElement|HTMLCanvasElement} getHtmlElementObj()
    HTMLElement Object getter
    Returns:
    {HTMLImageElement|HTMLCanvasElement}
  • {Number} getPixelsHigh()
    get height of in pixels
    Returns:
    {Number}
  • {Number} getPixelsWide()
    get width in pixels
    Returns:
    {Number}
  • handleLoadedTexture()
    handle loaded texture
  • initWithElement(element)
    init with HTML element
    Parameters:
    {HTMLImageElement|HTMLCanvasElement} element
  • initWithETCFile(file)
    init with ETC file
    Parameters:
    file
  • initWithPVRFile(file)
    init with PVR file
    Parameters:
    file
  • initWithPVRTCData(data, level, bpp, hasAlpha, length, pixelFormat)
    init with PVRTC data
    Parameters:
    data
    level
    bpp
    hasAlpha
    length
    pixelFormat
  • {boolean} isLoaded()
    check whether texture is loaded
    Returns:
    {boolean}
  • removeLoadedEventListener(target)
    remove listener from listeners by target
    Parameters:
    {cc.Node} target