Cocos Creator API

1.4.x

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

Texture2D

Extends RawAsset
Module: cc

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!

Properties

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

Inherited from RawAsset:

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

Methods

getPixelWidth ( ) Number

Get width in pixels.

returns:

type: Number

getPixelHeight ( ) Number

Get height of in pixels.

returns:

type: Number

getContentSize ( ) Size

Get content size.

returns:

type: Size

getContentSizeInPixels ( ) Size

Get content size in pixels.

returns:

type: Size

initWithElement
(
  • element
)

Init with HTML element.

name type description
element HTMLImageElement | HTMLCanvasElement

examples:

var img = new Image();
img.src = dataURL;
texture.initWithElement(img);
texture.handleLoadedTexture();

initWithData
(
  • data
  • pixelFormat
  • pixelsWide
  • pixelsHigh
  • contentSize
)
Boolean

Intializes with a texture2d with data.

name type description
data Array
pixelFormat Number
pixelsWide Number
pixelsHigh Number
contentSize Size

returns:

type: Boolean

initWithImage
(
  • uiImage
)
Boolean

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

name type description
uiImage HTMLImageElement