Cocos Creator API


Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.


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!

name WebGLTexture readOnly

WebGLTexture Object.

pixelFormat Number readOnly

Pixel format of the texture.

pixelWidth Number readOnly

Width in pixels.

pixelHeight Number readOnly

Height in pixels.

width Number

Content width in points.

height Number

Content height in points.

_uuid String private

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

getPixelWidth ( ) Number

Get width in pixels.


: Number

getPixelHeight ( ) Number

Get height of in pixels.


: Number

getContentSize ( ) Size

Get content size.


: Size

getContentSizeInPixels ( ) Size

Get content size in pixels.


: Size

  • element

Init with HTML element.

element HTMLImageElement | HTMLCanvasElement


var img = new Image();
img.src = dataURL;

  • data
  • pixelFormat
  • pixelsWide
  • pixelsHigh
  • contentSize

Intializes with a texture2d with data.

data Array
pixelFormat Number
pixelsWide Number
pixelsHigh Number
contentSize Size


  • uiImage

Initializes a texture from a UIImage object. Extensions to make it easy to create a CCTexture2D object from an image file. Note that RGBA type textures will have their alpha premultiplied - use the blending mode (gl.ONE, gl.ONE_MINUS_SRC_ALPHA).

uiImage HTMLImageElement


getHtmlElementObj ( ) HTMLImageElement | HTMLCanvasElement

HTMLElement Object getter.


: HTMLImageElement | HTMLCanvasElement

isLoaded ( ) Boolean

Check whether texture is loaded.


  • [premultiplied ]

Handler of texture loaded event.

premultiplied optional Boolean

description ( ) String

Description of cc.Texture2D.


: String

releaseTexture ( )

Release texture.

getPixelFormat ( ) Number

Pixel format of the texture.


: Number

hasPremultipliedAlpha ( ) Boolean

Whether or not the texture has their Alpha premultiplied, support only in WebGl rendering mode.


hasMipmaps ( ) Boolean

Whether or not use mipmap, support only in WebGl rendering mode.


  • texParams
  • [magFilter ]
  • [wrapS ]
  • [wrapT ]

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}.

texParams Object | Number

texParams object or minFilter

magFilter optional Number
wrapS optional Texture2D.WrapMode
wrapT optional Texture2D.WrapMode

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index