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K,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;oBAClC,oBAAoB;oBACpB,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA,gBAAgB;oBAC1E,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE,QAAQ;wBAC7B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;qBACtC;iBACJ;gBACD,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA,MAAM;aAC7D;QACL,CAAC;KACJ,CAAA;IAhFG;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;+CACJ;IAE1B;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;wDACjB;IAEpC;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;qDAClC;IAExB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;gDACV;IAEtB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDACP;IAXX,cAAc;QAHlC,OAAO;QACP,IAAI,CAAC,qBAAqB,CAAC;QAC5B,2BAA2B;OACN,cAAc,CAmFlC;IAAD,qBAAC;KAAA;kBAnFoB,cAAc","file":"","sourceRoot":"/","sourcesContent":["\n\nconst { ccclass, menu, property } = cc._decorator;\n\n@ccclass\n@menu(\"扩展组件/FrameAnimation\")\n/**序列侦动画组件,用于相同时间间隔序列侦动画 */\nexport default class FrameAnimation extends cc.Component {\n\n @property({ tooltip: \"动画标记\" })\n tag: string = 'animation';\n @property({ type: cc.SpriteFrame, tooltip: \"精灵帧数组\" })\n spriteframes: cc.SpriteFrame[] = [];\n @property({ type: cc.Float, tooltip: \"帧动画切换图片的时间,即间隔时间\" })\n frameTime: number = 0.1; //帧动画切换图片的时间,即间隔时间\n @property({ tooltip: \"是否循环播放\" })\n loop: boolean = false; //是否循环播放\n @property({ tooltip: \"是否加载完自动播放\" })\n playOnLoad: boolean = false;\n\n private _isPlaying: boolean;\n private _loopCount: number;\n get isPlaying() { return this._isPlaying }\n private _time: number;\n get time() { return this._time; }\n private _sprite: cc.Sprite;\n private _endCallback?: (loopCount?: number) => void;\n\n onLoad() {\n this._isPlaying = false; //是否在播放\n this._time = 0; //播放时间控制\n this._sprite = this.getComponent(cc.Sprite);//获取组件\n if (!this._sprite) { //若组件为空则为其添加组件\n this._sprite = this.addComponent(cc.Sprite);\n }\n if (this.playOnLoad) { //如果用户选择playload属性则在场景开始时播放动画\n this.play();\n }\n }\n\n play(callback?: (loopCount?: number) => void, loop?: boolean) {\n if (this.spriteframes.length < 0) {\n return;\n }\n if (loop !== undefined) this.loop = loop;\n this._endCallback = callback;\n this._loopCount = 0;\n this._isPlaying = true;\n this._time = 0;\n this._sprite.spriteFrame = this.spriteframes[0];\n }\n\n stop() {\n this._isPlaying = false\n }\n\n update(dt: number) {\n if (!this._isPlaying) { //判断是否正在播放,不在播放可以直接返回\n return;\n }\n if (this.spriteframes.length < 0) { //判断精灵帧长度是否合法\n return;\n }\n this._time += dt; //获取播放时间\n var index = Math.floor(this._time / this.frameTime); //取整获得图片位置\n if (!this.loop) {//非循环播放\n if (index >= this.spriteframes.length) { //播放完毕\n this._isPlaying = false;\n if (this._endCallback) { //执行回调函数\n this._endCallback();\n }\n }\n else {//动画正在播放\n this._sprite.spriteFrame = this.spriteframes[index];\n }\n }\n else {//循环播放\n while (index >= this.spriteframes.length) {\n //使索引回到之前对应的索引\n index -= this.spriteframes.length;\n //数组长度 *间隔时间 = 一段时间段\n this._time -= (this.spriteframes.length * this.frameTime);//使时间段回到之前对应的时间段\n this._loopCount++;\n if (this._endCallback) { //执行回调函数\n this._endCallback(this._loopCount);\n }\n }\n this._sprite.spriteFrame = this.spriteframes[index];//更新索引\n }\n }\n}\n"]}