Class cc.Texture2D
- Defined in: CCTexture2D.js
- Extends cc.Class
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
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_A8
8-bit textures used as masks
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_AI88
16-bit textures used as masks
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_DEFAULT
Default texture format: RGBA8888
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_I8
8-bit intensity texture
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_PVRTC2
2-bit PVRTC-compressed texture: PVRTC2
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_PVRTC4
4-bit PVRTC-compressed texture: PVRTC4
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_RGB565
16-bit texture without Alpha channel
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_RGB5A1
16-bit textures: RGB5A1
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_RGB888
24-bit texture: RGBA888
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_RGBA4444
16-bit textures: RGBA4444
<static> <constant>
cc.Texture2D.PIXEL_FORMAT_RGBA8888
32-bit texture: RGBA8888
{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
-
{Number} bitsPerPixelForFormat(format)returns the bits-per-pixel of the in-memory OpenGL texture
- Parameters:
- format
- Returns:
- {Number}
-
drawAtPoint(point)draws a texture at a given point
- Parameters:
- {cc.Point} point
-
drawInRect(rect)draws a texture inside a rect
- Parameters:
- {cc.Rect} rect
-
generateMipmap()Generates mipmap images for the texture.
It only works if the texture size is POT (power of 2). -
{cc.Size} getContentSize()content size
- Returns:
- {cc.Size}
-
{HTMLElement} getHtmlElementObj()HTMLElement Object getter
- Returns:
- {HTMLElement}
-
getMaxS()texture max S
-
getMaxT()texture max T
-
{WebGLTexture} getName()get WebGLTexture Object
- Returns:
- {WebGLTexture}
-
{Number} getPixelFormat()pixel format of the texture
- Returns:
- {Number}
-
{Number} getPixelsHigh()height in pixels
- Returns:
- {Number}
-
{Number} getPixelsWide()width in pixels
- Returns:
- {Number}
-
{cc.GLProgram} getShaderProgram()return shader program used by drawAtPoint and drawInRect
- Returns:
- {cc.GLProgram}
-
{Boolean} hasPremultipliedAlpha()whether or not the texture has their Alpha premultiplied
- Returns:
- {Boolean}
-
{Boolean} initWithData(data, pixelFormat, pixelsWide, pixelsHigh, contentSize)Intializes with a texture2d with data
- Parameters:
- {Array} data
- {Number} pixelFormat
- {Number} pixelsWide
- {Number} pixelsHigh
- {cc.Size} contentSize
- Returns:
- {Boolean}
-
{Boolean} initWithETCFile(file)Initializes a texture from a ETC file (note: initWithETCFile does not support on HTML5)
- Parameters:
- {String} file
- Returns:
- {Boolean}
-
{Boolean} initWithImage(uiImage)Initializes a texture from a UIImage object
- Parameters:
- uiImage
- Returns:
- {Boolean}
-
{Boolean} initWithPVRFile(file)Initializes a texture from a PVR file
- Parameters:
- {String} file
- Returns:
- {Boolean}
-
{Boolean} initWithPVRTCData(data, level, bpp, hasAlpha, length, pixelFormat)Initializes a texture from a PVRTC buffer
- Parameters:
- {Array} data
- {Number} level
- {Number} bpp
- {Boolean} hasAlpha
- {Number} length
- {Number} pixelFormat
- Returns:
- {Boolean}
-
{Boolean} initWithString(text, fontName, fontSize, dimensions, hAlignment, vAlignment)Initializes a texture from a string with dimensions, alignment, font name and font size (note: initWithString does not support on HTML5)
- Parameters:
- {String} text
- {String | cc.FontDefinition} fontName
- or fontDefinition
- {Number} fontSize
- {cc.Size} dimensions
- {Number} hAlignment
- {Number} vAlignment
- Returns:
- {Boolean}
-
releaseData(data)These functions are needed to create mutable textures
- Parameters:
- {Array} data
-
setAliasTexParameters()sets alias texture parameters: GL_TEXTURE_MIN_FILTER = GL_NEAREST GL_TEXTURE_MAG_FILTER = GL_NEAREST
-
setAntiAliasTexParameters()sets antialias texture parameters:
- GL_TEXTURE_MIN_FILTER = GL_NEAREST
- GL_TEXTURE_MAG_FILTER = GL_NEAREST -
setShaderProgram(shaderProgram)set shader program used by drawAtPoint and drawInRect
- Parameters:
- {cc.GLProgram} shaderProgram
-
setTexParameters(texParams)sets the min filter, mag filter, wrap s and wrap t texture parameters.
If the texture size is NPOT (non power of 2), then in can only use gl.CLAMP_TO_EDGE in gl.TEXTURE_WRAP_{S,T}.- Parameters:
- texParams
-
{String} stringForFormat()returns the pixel format.
- Returns:
- {String}