Cocos Creator API

1.0.0

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

returns:

type: Boolean

getHtmlElementObj ( ) HTMLImageElement | HTMLCanvasElement

HTMLElement Object getter.

returns:

type: HTMLImageElement | HTMLCanvasElement

isLoaded ( ) Boolean

Check whether texture is loaded.

returns:

type: Boolean

handleLoadedTexture
(
  • [premultiplied ]
)

Handler of texture loaded event.

name type description
premultiplied optional Boolean

description ( ) String

Description of cc.Texture2D.

returns:

type: String

releaseTexture ( )

Release texture.

getPixelFormat ( ) Number

Pixel format of the texture.

returns:

type: Number

hasPremultipliedAlpha ( ) Boolean

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

returns:

type: Boolean

hasMipmaps ( ) Boolean

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

returns:

type: Boolean

setTexParameters
(
  • 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}.

name type description
texParams Object | Number

texParams object or minFilter

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

createNodeByInfo
(
  • Info
  • callback
)

Inherited from RawAsset:

Create a new node in the scene.
If this type of asset dont have its corresponding node type, this method should be null.

name type description
Info Object
callback Function
  • error String

    null or the error info

  • node Object

    the created node or null

isRawAssetType
(
  • ctor
)
Boolean private

Inherited from RawAsset:

name type description
ctor Function

returns:

type: Boolean

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