AnimationClip 类型
继承于 Asset
模块: cc
动画剪辑,用于存储动画数据。
索引
属性(properties)
durationNumber动画的持续时间。sampleNumber动画的帧速率。speedNumber动画的播放速度。wrapModeWrapMode动画的循环模式。curveDataObject曲线数据。eventsObject[]事件数据。rawUrlString返回该资源的原始文件的 URL,如果不支持 RAW 文件,它将返回一个空字符串。rawUrlsString[]返回该资源的原文件的 URL 数组,如果不支持 RAW 文件,它将返回一个空数组。_rawFilesString[]在 lite 版的 Fireball 里,raw asset 并不仅仅是在 properties 里声明了 rawType 才有, 而是每个 asset 都能指定自己的 raw file url。这些 url 就存在 _rawFiles 字段中。 AssetLibrary 并不会帮你加载这些 url,除非你声明了 rawType。 在 Creator 里,_rawFiles 保留了下来,为了复用 cocos 引擎原有实现,直接用 _rawFiles 来加载 Asset 在 import 之前的源文件。_uuidString_nameString_objFlagsNumbernameString该对象的名称。isValidBoolean表示该对象是否可用(被销毁后将不可用)。
方法
createWithSpriteFrames使用一组序列帧图片来创建动画剪辑serialize应 AssetDB 要求提供这个方法createNode使用该资源在场景中创建一个新节点。
如果这类资源没有相应的节点类型,该方法应该是空的。_setRawFilesSet raw file names for this asset._preloadRawFilesPreload raw files when loading scene.destroy销毁该对象,并释放所有它对其它对象的引用。
销毁后,CCObject 不再可用。您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。 实际销毁操作会延迟到当前帧渲染前执行。_destructClear 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; } } }
_onPreDestroyCalled before the object being destroyed._serializeThe customized serialization for this object. (Editor Only)_deserializeInit this object from the custom serialized data.
Details
属性(properties)
duration
动画的持续时间。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/animation/animation-clip.js:21 |
sample
动画的帧速率。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/animation/animation-clip.js:31 |
speed
动画的播放速度。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/animation/animation-clip.js:41 |
wrapMode
动画的循环模式。
| meta | description |
|---|---|
| 类型 | WrapMode |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/animation/animation-clip.js:51 |
curveData
曲线数据。
| meta | description |
|---|---|
| 类型 | Object |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/animation/animation-clip.js:61 |
示例
{
// 根节点不用查找路径
// root properties
props: {
x: [
{ frame: 0, value: 0, curve: [0,0.5,0.5,1] },
{ frame: 1, value: 200, curve: null }
]
},
comps: {
// component
'comp-1': {
// component properties
'prop-1': [
{ frame: 0, value: 10, curve: [0,0.5,0.5,1] },
{ frame: 1, value: 20, curve: null }
]
}
},
paths: {
// key 为节点到root的路径名, 通过cc.find找到
'foo/bar': {
// node properties
props: {
x: [
{ frame: 0, value: 0, curve: [0,0.5,0.5,1]
{ frame: 1, value: 200, curve: null }
]
},
comps: {
// component
'comp-1': {
// component property
'prop-1': [
{ frame: 0, value: 10, curve: [0,0.5,0.
{ frame: 1, value: 20, curve: null }
]
}
}
},
'hello': {
props: {
position: [
{
frame: 0,
value: [0,0],
motionPath: [
[320, 240, 0, 240, 640, 240],
[640, 0, 400, 0, 1000, 0]
]
},
{ frame: 5, value: [640, 480] }
]
}
}
}
}
}
events
事件数据。
| meta | description |
|---|---|
| 类型 | Object[] |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/animation/animation-clip.js:73 |
示例
// frame : The exactly time in second.
// func : Callback function name
// params : Callback parameters
[
{ frame: 0, func: 'onAnimationEvent1', params:['param-1', 'param-2'] },
{ frame: 2, func: 'onAnimationEvent3', params:['param-1', 'param-2'] },
{ frame: 3, func: 'onAnimationEvent2', params:['param-1'] },
// The second event at frame 3
{ frame: 3, func: 'onAnimationEvent4', params:['param-1'] },
{ frame: 4, func: 'onAnimationEvent4', params:['param-1'] }
]
rawUrl
返回该资源的原始文件的 URL,如果不支持 RAW 文件,它将返回一个空字符串。
| meta | description |
|---|---|
| 类型 | String |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCAsset.js:53 |
rawUrls
返回该资源的原文件的 URL 数组,如果不支持 RAW 文件,它将返回一个空数组。
| meta | description |
|---|---|
| 类型 | String[] |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCAsset.js:77 |
_rawFiles
在 lite 版的 Fireball 里,raw asset 并不仅仅是在 properties 里声明了 rawType 才有, 而是每个 asset 都能指定自己的 raw file url。这些 url 就存在 _rawFiles 字段中。 AssetLibrary 并不会帮你加载这些 url,除非你声明了 rawType。 在 Creator 里,_rawFiles 保留了下来,为了复用 cocos 引擎原有实现,直接用 _rawFiles 来加载 Asset 在 import 之前的源文件。
| meta | description |
|---|---|
| 类型 | String[] |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCAsset.js:104 |
_uuid
| meta | description |
|---|---|
| 类型 | String |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCRawAsset.js:49 |
_name
| meta | description |
|---|---|
| 类型 | String |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:50 |
_objFlags
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:57 |
name
该对象的名称。
| meta | description |
|---|---|
| 类型 | String |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:208 |
示例
obj.name = "New Obj";
isValid
表示该对象是否可用(被销毁后将不可用)。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:225 |
示例
cc.log(obj.isValid);
方法
createWithSpriteFrames
使用一组序列帧图片来创建动画剪辑
| meta | description |
|---|---|
| 返回 | AnimationClip |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/animation/animation-clip.js:88 |
参数列表
spriteFrames[SpriteFrame]sampleNumber
示例
var clip = cc.AnimationClip.createWithSpriteFrames(spriteFrames, 10);
serialize
应 AssetDB 要求提供这个方法
| meta | description |
|---|---|
| 返回 | String |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCAsset.js:143 |
createNode
使用该资源在场景中创建一个新节点。
如果这类资源没有相应的节点类型,该方法应该是空的。
| meta | description |
|---|---|
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCAsset.js:154 |
参数列表
_setRawFiles
Set raw file names for this asset.
| meta | description |
|---|---|
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCAsset.js:168 |
参数列表
rawFilesString[]
_preloadRawFiles
Preload raw files when loading scene.
| meta | description |
|---|---|
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/assets/CCAsset.js:179 |
参数列表
destroy
销毁该对象,并释放所有它对其它对象的引用。
销毁后,CCObject 不再可用。您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。
实际销毁操作会延迟到当前帧渲染前执行。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:246 |
示例
obj.destroy();
_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 |
|---|---|
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:379 |
_onPreDestroy
Called before the object being destroyed.
| meta | description |
|---|---|
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:412 |
_serialize
The customized serialization for this object. (Editor Only)
| meta | description |
|---|---|
| 返回 | object |
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:437 |
参数列表
exportingBoolean
_deserialize
Init this object from the custom serialized data.
| meta | description |
|---|---|
| 定义于 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:447 |
参数列表
dataObject the serialized json datactx_Deserializer