RenderTexture 类型

继承于 Texture2D

模块: cc 父模块: cc

Render textures are textures that can be rendered to.

索引

属性(properties)
  • genMipmaps Boolean 是否为纹理设置生成 mipmaps。
  • packable Boolean 设置纹理是否允许参与合图。
  • loaded Boolean 贴图是否已经成功加载
  • width Number 贴图像素宽度
  • height Number 贴图像素高度
  • url String 资源的原生文件的真实url,只在资源被加载后以及没有启用延迟加载时才有效。
  • 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 后将不可用)。
方法
  • initWithSize 初始化 render texture
  • readPixels 从 render texture 读取像素数据,数据类型为 RGBA 格式的 Uint8Array 数组。
  • 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 时预乘选项是否开启。
  • handleLoadedTexture 贴图加载事件处理器。
  • description cc.Texture2D 描述。
  • releaseTexture 释放纹理,请使用 destroy 替代。
  • setTexParameters 设置纹理包装模式。
  • setFilters 设置纹理贴图缩小和放大过滤器算法选项。
  • setFlipY 设置贴图的纵向翻转选项。
  • setPremultiplyAlpha 设置贴图的预乘选项。
  • hasEventListener 检查事件目标对象是否有为特定类型的事件注册的回调。
  • on 注册事件目标的特定事件类型回调。
  • off 删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。
  • targetOff 在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。
  • once 注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。
  • dispatchEvent 通过事件对象派发事件
  • toString Returns the asset's url....
  • serialize 应 AssetDB 要求提供这个方法
  • createNode 使用该资源在场景中创建一个新节点。
  • _setRawAsset Set native file name for this asset.
  • _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)

genMipmaps

是否为纹理设置生成 mipmaps。

meta description
类型 Boolean
定义于 cocos2d/core/assets/CCTexture2D.js:329
packable

设置纹理是否允许参与合图。 如果需要在自定义 Effect 中使用纹理 UV,需要禁止该选项。

meta description
类型 Boolean
定义于 cocos2d/core/assets/CCTexture2D.js:349
loaded

贴图是否已经成功加载

meta description
类型 Boolean
定义于 cocos2d/core/assets/CCTexture2D.js:383
width

贴图像素宽度

meta description
类型 Number
定义于 cocos2d/core/assets/CCTexture2D.js:392
height

贴图像素高度

meta description
类型 Number
定义于 cocos2d/core/assets/CCTexture2D.js:401
url

资源的原生文件的真实url,只在资源被加载后以及没有启用延迟加载时才有效。 nativeUrl 与 url 的区别在于,url 是资源最终路径,所以 url 不需要再经过 md5 以及子包的路径转换, 另外某些带缓存机制的小游戏平台(微信等)上url可能会指向临时文件路径或者缓存路径,如果你需要在这些平台上使用资源的原生文件,请使用url,避免使用nativeUrl

meta description
类型 String
定义于 cocos2d/core/assets/CCAsset.js:68
nativeUrl

返回该资源对应的目标平台资源的 URL,如果没有将返回一个空字符串。

meta description
类型 String
定义于 cocos2d/core/assets/CCAsset.js:85
_native

Serializable url for native asset.

meta description
类型 String
定义于 cocos2d/core/assets/CCAsset.js:123
_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.

meta description
类型 Object
定义于 cocos2d/core/assets/CCAsset.js:131
_uuid
meta description
类型 String
定义于 cocos2d/core/assets/CCRawAsset.js:46
_name
meta description
类型 String
定义于 cocos2d/core/platform/CCObject.js:76
_objFlags
meta description
类型 Number
定义于 cocos2d/core/platform/CCObject.js:83
name

该对象的名称。

meta description
类型 String
定义于 cocos2d/core/platform/CCObject.js:240
示例
obj.name = "New Obj";
isValid

表示该对象是否可用(被 destroy 后将不可用)。
当一个对象的 destroy 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 isValid 就会返回 false,而当前帧内 isValid 仍然会是 true。如果希望判断当前帧是否调用过 destroy,请使用 cc.isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。

meta description
类型 Boolean
定义于 cocos2d/core/platform/CCObject.js:258
示例
var node = new cc.Node();
cc.log(node.isValid);    // true
node.destroy();
cc.log(node.isValid);    // true, still valid in this frame
// after a frame...
cc.log(node.isValid);    // false, destroyed in the end of last frame

方法

initWithSize

初始化 render texture

meta description
定义于 cocos2d/core/assets/CCRenderTexture.js:22
参数列表
readPixels

从 render texture 读取像素数据,数据类型为 RGBA 格式的 Uint8Array 数组。 默认每次调用此函数会生成一个大小为 (长 x 高 x 4) 的 Uint8Array。 你可以通过传入 data 来接收像素数据,也可以通过传参来指定需要读取的区域的像素。

meta description
返回 Uint8Array
定义于 cocos2d/core/assets/CCRenderTexture.js:97
参数列表
getImpl

返回渲染器内部贴图对象

meta description
定义于 cocos2d/core/assets/CCTexture2D.js:420
update

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

meta description
定义于 cocos2d/core/assets/CCTexture2D.js:439
参数列表
initWithElement

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

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

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

meta description
返回 Boolean
定义于 cocos2d/core/assets/CCTexture2D.js:548
参数列表
getHtmlElementObj

获取当前贴图对应的 HTML Image 或 Canvas 对象,只在 Web 平台下有效。
注意:
texture 默认参与动态合图,如果需要获取到正确的 Html 元素对象,需要先设置 texture.packable 为 false

meta description
返回 HTMLImageElement | HTMLCanvasElement
定义于 cocos2d/core/assets/CCTexture2D.js:590
destroy

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

meta description
返回 Boolean
定义于 cocos2d/core/assets/CCTexture2D.js:605
getPixelFormat

获取纹理的像素格式。

meta description
返回 Number
定义于 cocos2d/core/assets/CCTexture2D.js:624
hasPremultipliedAlpha

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

meta description
返回 Boolean
定义于 cocos2d/core/assets/CCTexture2D.js:636
handleLoadedTexture

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

meta description
定义于 cocos2d/core/assets/CCTexture2D.js:647
参数列表
description

cc.Texture2D 描述。

meta description
返回 String
定义于 cocos2d/core/assets/CCTexture2D.js:694
releaseTexture

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

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

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

meta description
定义于 cocos2d/core/assets/CCTexture2D.js:717
参数列表
setFilters

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

meta description
定义于 cocos2d/core/assets/CCTexture2D.js:735
参数列表
setFlipY

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

meta description
定义于 cocos2d/core/assets/CCTexture2D.js:751
参数列表
setPremultiplyAlpha

设置贴图的预乘选项。

meta description
定义于 cocos2d/core/assets/CCTexture2D.js:766
参数列表
hasEventListener

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

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

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

meta description
返回 Function
定义于 cocos2d/core/event/event-target.js:77
参数列表
  • type String A string representing the event type to listen for.
  • callback Function The callback that will be invoked when the event is dispatched.
                           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
示例
eventTarget.on('fire', function () {
    cc.log("fire in the hole");
}, node);
off

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

meta description
定义于 cocos2d/core/event/event-target.js:119
参数列表
  • 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
示例
// register fire eventListener
var callback = eventTarget.on('fire', function () {
    cc.log("fire in the hole");
}, target);
// remove fire event listener
eventTarget.off('fire', callback, target);
// remove all fire event listeners
eventTarget.off('fire');
targetOff

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

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

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

meta description
定义于 cocos2d/core/event/event-target.js:182
参数列表
  • type String A string representing the event type to listen for.
  • callback Function The callback that will be invoked when the event is dispatched.
                           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
示例
eventTarget.once('fire', function () {
    cc.log("this is the callback and will be invoked only once");
}, node);
dispatchEvent

通过事件对象派发事件

meta description
定义于 cocos2d/core/event/event-target.js:208
参数列表
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.

meta description
返回 String
定义于 cocos2d/core/assets/CCAsset.js:184
serialize

应 AssetDB 要求提供这个方法

meta description
返回 String
定义于 cocos2d/core/assets/CCAsset.js:198
createNode

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

meta description
定义于 cocos2d/core/assets/CCAsset.js:209
参数列表
_setRawAsset

Set native file name for this asset.

meta description
定义于 cocos2d/core/assets/CCAsset.js:224
参数列表
_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; } } }

meta description
定义于 cocos2d/core/platform/CCObject.js:427
_onPreDestroy

Called before the object being destroyed.

meta description
定义于 cocos2d/core/platform/CCObject.js:460
_serialize

The customized serialization for this object. (Editor Only)

meta description
返回 object
定义于 cocos2d/core/platform/CCObject.js:485
参数列表
_deserialize

Init this object from the custom serialized data.

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

事件

load Event

模块: cc 父模块: cc

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

索引

Details

条与 "" 相匹配的结果

    没有与 "" 匹配的结果