• Texture2D 类型
    • 索引
      • 属性(properties)
      • 方法
      • 事件
  • Details
    • 属性(properties)
      • url
      • loaded
      • width
      • height
      • nativeUrl
      • _native
      • _nativeAsset
      • _uuid
      • _name
      • _objFlags
      • name
      • 示例
      • isValid
      • 示例
    • 方法
      • getImpl
      • update
        • 参数列表
      • initWithElement
        • 参数列表
      • 示例
      • initWithData
        • 参数列表
      • getHtmlElementObj
      • destroy
      • getPixelFormat
      • hasPremultipliedAlpha
      • hasMipmap
      • handleLoadedTexture
        • 参数列表
      • description
      • releaseTexture
      • setTexParameters
        • 参数列表
      • setFilters
        • 参数列表
      • setFlipY
        • 参数列表
      • setPremultiplyAlpha
        • 参数列表
      • setMipmap
        • 参数列表
      • toString
      • serialize
      • createNode
        • 参数列表
      • _setRawAsset
        • 参数列表
      • hasEventListener
        • 参数列表
      • on
        • 参数列表
      • 示例
      • off
        • 参数列表
      • 示例
      • targetOff
        • 参数列表
      • once
        • 参数列表
      • 示例
      • emit
        • 参数列表
      • 示例
      • dispatchEvent
        • 参数列表
      • _destruct
      • _onPreDestroy
      • _serialize
        • 参数列表
      • _deserialize
        • 参数列表
    • 事件
  • load Event
  • 索引
  • Details

    Texture2D 类型

    继承于 Asset, EventTarget(mixin)

    模块: cc父模块: cc

    This class allows to easily create OpenGL or Canvas 2D textures from images or raw data.

    索引

    属性(properties)
    • url String 贴图文件的 url,当贴图不是由文件创建时值可能为空
    • loaded Boolean 贴图是否已经成功加载
    • width Number 贴图像素宽度
    • height Number 贴图像素高度
    • nativeUrl String 返回该资源对应的目标平台资源的 URL,如果没有将返回一个空字符串。
    • _native String Serializable url for native asset.
    • _nativeAsset Object The underlying native asset of this asset if one is available….
    • _uuid String
    • _name String
    • _objFlags Number
    • name String 该对象的名称。
    • isValid Boolean 表示该对象是否可用(被 destroy 后将不可用)。
    方法
    • getImpl 返回渲染器内部贴图对象
    • update Update texture options, not available in Canvas render mode….
    • initWithElement 用 HTML Image 或 Canvas 对象初始化贴图。
    • initWithData 使用一个存储在 Unit8Array 中的图像数据(raw data)初始化数据。
    • getHtmlElementObj 获取当前贴图对应的 HTML Image 或 Canvas 对象,只在 Web 平台下有效。
    • destroy 销毁该贴图,并立即释放它对应的显存。
    • getPixelFormat 获取纹理的像素格式。
    • hasPremultipliedAlpha 检查纹理在上传 GPU 时预乘选项是否开启。
    • hasMipmap 检查问题在上传 GPU 时是否生成 mipmap。
    • handleLoadedTexture 贴图加载事件处理器。
    • description cc.Texture2D 描述。
    • releaseTexture 释放纹理,请使用 destroy 替代。
    • setTexParameters 设置纹理包装模式。
    • setFilters 设置纹理贴图缩小和放大过滤器算法选项。
    • setFlipY 设置贴图的纵向翻转选项。
    • setPremultiplyAlpha 设置贴图的预乘选项。
    • setMipmap 是否为纹理设置生成 mipmaps。
    • toString Returns the asset's url….
    • serialize 应 AssetDB 要求提供这个方法
    • createNode 使用该资源在场景中创建一个新节点。
    • _setRawAsset Set native file name for this asset.
    • hasEventListener 检查事件目标对象是否有为特定类型的事件注册的回调。
    • on 注册事件目标的特定事件类型回调。
    • off 删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。
    • targetOff 在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。
    • once 注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。
    • emit 通过事件名发送自定义事件
    • dispatchEvent 通过事件对象派发事件
    • _destruct Clear all references in the instance….
    • _onPreDestroy Called before the object being destroyed.
    • _serialize The customized serialization for this object. (Editor Only)
    • _deserialize Init this object from the custom serialized data.
    事件
    • load 当该资源加载成功后触发该事件

    Details

    属性(properties)

    url
    贴图文件的 url,当贴图不是由文件创建时值可能为空
    metadescription
    类型String
    定义于cocos2d/core/assets/CCTexture2D.js:296
    loaded
    贴图是否已经成功加载
    metadescription
    类型Boolean
    定义于cocos2d/core/assets/CCTexture2D.js:308
    width
    贴图像素宽度
    metadescription
    类型Number
    定义于cocos2d/core/assets/CCTexture2D.js:317
    height
    贴图像素高度
    metadescription
    类型Number
    定义于cocos2d/core/assets/CCTexture2D.js:326
    nativeUrl
    返回该资源对应的目标平台资源的 URL,如果没有将返回一个空字符串。
    metadescription
    类型String
    定义于cocos2d/core/assets/CCAsset.js:70
    _native
    Serializable url for native asset.
    metadescription
    类型String
    定义于cocos2d/core/assets/CCAsset.js:108
    _nativeAsset
    The underlying native asset of this asset if one is available.This property can be used to access additional details or functionality releated to the asset.This property will be initialized by the loader if _native is available.
    metadescription
    类型Object
    定义于cocos2d/core/assets/CCAsset.js:116
    _uuid

    metadescription
    类型String
    定义于cocos2d/core/assets/CCRawAsset.js:46
    _name

    metadescription
    类型String
    定义于cocos2d/core/platform/CCObject.js:76
    _objFlags

    metadescription
    类型Number
    定义于cocos2d/core/platform/CCObject.js:83
    name
    该对象的名称。
    metadescription
    类型String
    定义于cocos2d/core/platform/CCObject.js:243
    示例
    1. obj.name = "New Obj";
    isValid
    表示该对象是否可用(被 destroy 后将不可用)。当一个对象的 destroy 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 isValid 就会返回 false,而当前帧内 isValid 仍然会是 true。如果希望判断当前帧是否调用过 destroy,请使用 cc.isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。
    metadescription
    类型Boolean
    定义于cocos2d/core/platform/CCObject.js:261
    示例
    1. var node = new cc.Node();
    2. cc.log(node.isValid); // true
    3. node.destroy();
    4. cc.log(node.isValid); // true, still valid in this frame
    5. // after a frame...
    6. cc.log(node.isValid); // false, destroyed in the end of last frame

    方法

    getImpl

    返回渲染器内部贴图对象

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:343
    update

    Update texture options, not available in Canvas render mode.image, format, premultiplyAlpha can not be updated in native.

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:362
    参数列表
    • options Object
      • image DOMImageElement
      • mipmap Boolean
      • format PixelFormat
      • minFilter Filter
      • magFilter Filter
      • wrapS WrapMode
      • wrapT WrapMode
      • premultiplyAlpha Boolean
    initWithElement

    用 HTML Image 或 Canvas 对象初始化贴图。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:436
    参数列表
    • element HTMLImageElement | HTMLCanvasElement
    示例
    1. var img = new Image();
    2. img.src = dataURL;
    3. texture.initWithElement(img);
    initWithData

    使用一个存储在 Unit8Array 中的图像数据(raw data)初始化数据。

    metadescription
    返回Boolean
    定义于cocos2d/core/assets/CCTexture2D.js:465
    参数列表
    • data TypedArray
    • pixelFormat Number
    • pixelsWidth Number
    • pixelsHeight Number
    getHtmlElementObj

    获取当前贴图对应的 HTML Image 或 Canvas 对象,只在 Web 平台下有效。

    metadescription
    返回HTMLImageElement | HTMLCanvasElement
    定义于cocos2d/core/assets/CCTexture2D.js:504
    destroy

    销毁该贴图,并立即释放它对应的显存。(继承自 cc.Object.destroy)销毁后,该对象不再可用。您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。

    metadescription
    返回Boolean
    定义于cocos2d/core/assets/CCTexture2D.js:515
    getPixelFormat

    获取纹理的像素格式。

    metadescription
    返回Number
    定义于cocos2d/core/assets/CCTexture2D.js:534
    hasPremultipliedAlpha

    检查纹理在上传 GPU 时预乘选项是否开启。

    metadescription
    返回Boolean
    定义于cocos2d/core/assets/CCTexture2D.js:546
    hasMipmap

    检查问题在上传 GPU 时是否生成 mipmap。

    metadescription
    返回Boolean
    定义于cocos2d/core/assets/CCTexture2D.js:557
    handleLoadedTexture

    贴图加载事件处理器。v2.0 之后你将不在需要手动执行这个函数,它会在贴图加载成功之后自动执行。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:568
    参数列表
    • premultiplied Boolean
    description

    cc.Texture2D 描述。

    metadescription
    返回String
    定义于cocos2d/core/assets/CCTexture2D.js:617
    releaseTexture

    释放纹理,请使用 destroy 替代。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:628
    废弃(Deprecated)since v2.0
    setTexParameters

    设置纹理包装模式。若纹理贴图尺寸是 NPOT(non power of 2),则只能使用 Texture2D.WrapMode.CLAMP_TO_EDGE。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:640
    参数列表
    • wrapS Texture2D.WrapMode
    • wrapT Texture2D.WrapMode
    setFilters

    设置纹理贴图缩小和放大过滤器算法选项。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:658
    参数列表
    • minFilter Texture2D.Filter
    • magFilter Texture2D.Filter
    setFlipY

    设置贴图的纵向翻转选项。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:674
    参数列表
    • flipY Boolean
    setPremultiplyAlpha

    设置贴图的预乘选项。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:689
    参数列表
    • premultiply Boolean
    setMipmap

    是否为纹理设置生成 mipmaps。

    metadescription
    定义于cocos2d/core/assets/CCTexture2D.js:704
    参数列表
    • mipmap Boolean
    toString

    Returns the asset's url.

    The Asset object overrides the toString() method of the Object object.For Asset objects, the toString() method returns a string representation of the object.JavaScript calls the toString() method automatically when an asset is to be represented as a text value or when a texture is referred to in a string concatenation.

    metadescription
    返回String
    定义于cocos2d/core/assets/CCAsset.js:165
    serialize

    应 AssetDB 要求提供这个方法

    metadescription
    返回String
    定义于cocos2d/core/assets/CCAsset.js:179
    createNode

    使用该资源在场景中创建一个新节点。如果这类资源没有相应的节点类型,该方法应该是空的。

    metadescription
    定义于cocos2d/core/assets/CCAsset.js:190
    参数列表
    • callback Function
      • error String null or the error info
      • node Object the created node or null
    _setRawAsset

    Set native file name for this asset.

    metadescription
    定义于cocos2d/core/assets/CCAsset.js:205
    参数列表
    • filename String
    • inLibrary Boolean
    hasEventListener

    检查事件目标对象是否有为特定类型的事件注册的回调。

    metadescription
    返回Boolean
    定义于cocos2d/core/event/event-target.js:68
    参数列表
    • type String The type of event.
    on

    注册事件目标的特定事件类型回调。这种类型的事件应该被 emit 触发。

    metadescription
    返回Function
    定义于cocos2d/core/event/event-target.js:76
    参数列表
    • type String A string representing the event type to listen for.
    • callback Function The callback that will be invoked when the event is dispatched.
    1. The callback is ignored if it is a duplicate (the callbacks are unique).
    • arg1 Any arg1
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
      • target Object The target (this object) to invoke the callback, can be null
    示例
    1. eventTarget.on('fire', function () {
    2. cc.log("fire in the hole");
    3. }, node);
    off

    删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。

    metadescription
    定义于cocos2d/core/event/event-target.js:116
    参数列表
    • type String A string representing the event type being removed.
    • callback Function The callback to remove.
    • target Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removed
    示例
    1. // register fire eventListener
    2. var callback = eventTarget.on('fire', function () {
    3. cc.log("fire in the hole");
    4. }, target);
    5. // remove fire event listener
    6. eventTarget.off('fire', callback, target);
    7. // remove all fire event listeners
    8. eventTarget.off('fire');
    targetOff

    在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。这个函数无法删除当前 EventTarget 的所有事件监听器,也无法删除 target 参数所注册的所有事件监听器。这个函数只能删除 target 参数在当前 EventTarget 上注册的所有事件监听器。

    metadescription
    定义于cocos2d/core/event/event-target.js:150
    参数列表
    • target Object The target to be searched for all related listeners
    once

    注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。

    metadescription
    定义于cocos2d/core/event/event-target.js:163
    参数列表
    • type String A string representing the event type to listen for.
    • callback Function The callback that will be invoked when the event is dispatched.
    1. The callback is ignored if it is a duplicate (the callbacks are unique).
    • arg1 Any arg1
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
      • target Object The target (this object) to invoke the callback, can be null
    示例
    1. eventTarget.once('fire', function () {
    2. cc.log("this is the callback and will be invoked only once");
    3. }, node);
    emit

    通过事件名发送自定义事件

    metadescription
    定义于cocos2d/core/event/event-target.js:200
    参数列表
    • type String event type
    • arg1 Any First argument
    • arg2 Any Second argument
    • arg3 Any Third argument
    • arg4 Any Fourth argument
    • arg5 Any Fifth argument
    示例
    1. eventTarget.emit('fire', event);
    2. eventTarget.emit('fire', message, emitter);
    dispatchEvent

    通过事件对象派发事件

    metadescription
    定义于cocos2d/core/event/event-target.js:220
    参数列表
    • event Event
    _destruct

    Clear all references in the instance.

    NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

    metadescription
    定义于cocos2d/core/platform/CCObject.js:430
    _onPreDestroy

    Called before the object being destroyed.

    metadescription
    定义于cocos2d/core/platform/CCObject.js:463
    _serialize

    The customized serialization for this object. (Editor Only)

    metadescription
    返回object
    定义于cocos2d/core/platform/CCObject.js:488
    参数列表
    • exporting Boolean
    _deserialize

    Init this object from the custom serialized data.

    metadescription
    定义于cocos2d/core/platform/CCObject.js:498
    参数列表
    • data Object the serialized json data
    • ctx _Deserializer

    事件

    load Event

    模块: cc父模块: cc

    当该资源加载成功后触发该事件

    索引

    Details