2 Star 0 Fork 0

mirrors_cocos-creator/sprite-animation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sprite-animation-clip.js 4.34 KB
一键复制 编辑 原始数据 按行查看 历史

/**
* @class SpriteAnimationClip
*/
/**
* @namespace SpriteAnimationClip
*/
/**
* @class WrapMode
* @static
*/
var WrapMode = Fire.defineEnum({
/**
* @property Default
* @type {number}
*/
Default: -1,
/**
* @property Once
* @type {number}
*/
Once: -1,
/**
* @property Loop
* @type {number}
*/
Loop: -1,
/**
* @property PingPong
* @type {number}
*/
PingPong: -1,
/**
* @property ClampForever
* @type {number}
*/
ClampForever: -1
});
/**
* @class StopAction
* @static
*/
var StopAction = Fire.defineEnum({
/**
* Do nothing
* @property DoNothing
* @type {number}
*/
DoNothing: -1,
/**
* Set to default sprite when the sprite animation stopped
* @property DefaultSprite
* @type {number}
*/
DefaultSprite: 1,
/**
* Hide the sprite when the sprite animation stopped
* @property Hide
* @type {number}
*/
Hide: -1,
/**
* Destroy the entity the sprite belongs to when the sprite animation stopped
* @property Destroy
* @type {number}
*/
Destroy: -1
});
// ------------------------------------------------------------------
/// The structure to descrip a frame in the sprite animation clip
// ------------------------------------------------------------------
var FrameInfo = Fire.define('FrameInfo')
.prop('sprite', null, Fire.ObjectType(Fire.Sprite))
.prop('frames', 0, Fire.Integer_Obsoleted);
/**
* The sprite animation clip.
* @class SpriteAnimationClip
* @extends CustomAsset
* @constructor
*/
var SpriteAnimationClip = Fire.Class({
name: 'Fire.SpriteAnimationClip',
//
extends: Fire.CustomAsset,
//
constructor: function() {
// the array of the end frame of each frame info
this._frameInfoFrames = null;
},
//
properties: {
/**
* Default wrap mode.
* @property wrapMode
* @type {SpriteAnimationClip.WrapMode}
* @default SpriteAnimationClip.WrapMode.Default
*/
wrapMode: {
default: WrapMode.Default,
type: WrapMode
},
/**
* The default type of action used when the animation stopped.
* @property stopAction
* @type {SpriteAnimationClip.StopAction}
* @default SpriteAnimationClip.StopAction.DoNothing
*/
stopAction: {
default: StopAction.DoNothing,
type: StopAction
},
/**
* The default speed of the animation clip.
* @property speed
* @type {number}
* @default 1
*/
speed: 1,
//
_frameRate: 60,
/**
* The sample rate used in this animation clip.
* @property frameRate
* @type {number}
* @default 60
*/
frameRate: {
get: function() {
return this._frameRate;
},
set: function() {
if (value !== this._frameRate) {
this._frameRate = Math.round(Math.max(value, 1));
}
}
},
/**
* The frame infos in the sprite animation clips.
* are array of {sprite: Sprite, frames: Sustained_how_many_frames}
* @property frameInfos
* @type {object[]}
* @default []
*/
frameInfos:{
default: [],
type: FrameInfo
}
},
//
getTotalFrames: function() {
var frames = 0;
for (var i = 0; i < this.frameInfos.length; ++i) {
frames += this.frameInfos[i].frames;
}
return frames;
},
//
getFrameInfoFrames: function() {
if (this._frameInfoFrames === null) {
this._frameInfoFrames = new Array(this.frameInfos.length);
var totalFrames = 0;
for (var i = 0; i < this.frameInfos.length; ++i) {
totalFrames += this.frameInfos[i].frames;
this._frameInfoFrames[i] = totalFrames;
}
}
return this._frameInfoFrames;
}
});
SpriteAnimationClip.WrapMode = WrapMode;
SpriteAnimationClip.StopAction = StopAction;
Fire.addCustomAssetMenu(SpriteAnimationClip, "New Sprite Animation");
Fire.SpriteAnimationClip = SpriteAnimationClip;
module.exports = SpriteAnimationClip;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_cocos-creator/sprite-animation.git
[email protected]:mirrors_cocos-creator/sprite-animation.git
mirrors_cocos-creator
sprite-animation
sprite-animation
master

搜索帮助