Cocos Creator API

1.2.0

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

Texture2D

继承于 RawAsset
模块: 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

继承自 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

方法

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

initWithElement
(
  • element
)

Init with HTML element.

名称 类型 描述
element HTMLImageElement | HTMLCanvasElement

示例:

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.

名称 类型 描述
data Array
pixelFormat Number
pixelsWide Number
pixelsHigh Number
contentSize Size

返回:

类型: 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).

名称 类型 描述
uiImage HTMLImageElement

返回:

类型: Boolean

getHtmlElementObj ( ) HTMLImageElement | HTMLCanvasElement

HTMLElement Object getter.

返回:

类型: HTMLImageElement | HTMLCanvasElement

isLoaded ( ) Boolean

Check whether texture is loaded.

返回:

类型: Boolean

handleLoadedTexture
(
  • [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.

返回:

类型: Boolean

hasMipmaps ( ) Boolean

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

返回:

类型: 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}.

名称 类型 描述
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