|
|
@@ -8,6 +8,9 @@ const { ccclass, property, executeInEditMode, playOnFocus } = cc._decorator;
|
|
|
* #### gotoAndPlay 跳转到某帧并播放
|
|
|
* #### gotoAndStop 跳转到某帧并停止播放
|
|
|
* #### isPlayEnd 是否播放结束
|
|
|
+ * ### 开放的事件
|
|
|
+ * #### completeTimes 单次播完完成事件
|
|
|
+ * #### complete 全部次数完成事件
|
|
|
* @author 薛鸿潇
|
|
|
*/
|
|
|
@ccclass
|
|
|
@@ -24,20 +27,21 @@ export default class FrameAnimation extends cc.Component {
|
|
|
@property({ displayName: "每帧回调", type: cc.Component.EventHandler }) onFrameCall: cc.Component.EventHandler = new cc.Component.EventHandler();
|
|
|
@property({ displayName: "结束回调", type: cc.Component.EventHandler }) onCompleteCall: cc.Component.EventHandler = new cc.Component.EventHandler();
|
|
|
/** 编辑器预览 bug待修复*/
|
|
|
- // private _edit_play: boolean = false;
|
|
|
- // @property({ displayName: '编辑器预览' })
|
|
|
- // get edit_play(): boolean {
|
|
|
- // if (this._edit_play && this.frameNum) {
|
|
|
- // this.play();
|
|
|
- // this._edit_play = false;
|
|
|
- // cc.log(this._edit_play)
|
|
|
- // }
|
|
|
- // this.running = this._edit_play;
|
|
|
- // return this._edit_play;
|
|
|
- // }
|
|
|
- // set edit_play(v: boolean) {
|
|
|
- // this._edit_play = v;
|
|
|
- // }
|
|
|
+ private _edit_play: boolean = false;
|
|
|
+ @property({ displayName: '编辑器预览' })
|
|
|
+ get edit_play(): boolean {
|
|
|
+ if (this._edit_play && !this.edit_playing) {
|
|
|
+ this.edit_playing = true;
|
|
|
+ this.play();
|
|
|
+ }
|
|
|
+ this.running = this._edit_play;
|
|
|
+ return this._edit_play;
|
|
|
+ }
|
|
|
+ set edit_play(v: boolean) {
|
|
|
+ this._edit_play = v;
|
|
|
+ }
|
|
|
+ /** 编辑器是否正在播放 */
|
|
|
+ private edit_playing = false;
|
|
|
|
|
|
/** 动画帧数量 */
|
|
|
public frameNum: number = 0;
|
|
|
@@ -45,23 +49,23 @@ export default class FrameAnimation extends cc.Component {
|
|
|
public frameIndex: number = 0;
|
|
|
/** 下一帧下标 */
|
|
|
public nextFrameIndex: number = 0;
|
|
|
-
|
|
|
+ /** 是否允许播放 */
|
|
|
public running: boolean = true;
|
|
|
-
|
|
|
- private m_render: cc.Sprite;
|
|
|
-
|
|
|
+ /** 精灵组件 */
|
|
|
+ private comp_spr: cc.Sprite;
|
|
|
+ /** 播放下一帧的倒计时 */
|
|
|
private time: number = 0;
|
|
|
-
|
|
|
+ /** 每完成一轮的回调 */
|
|
|
public completeTimesCallback: Function;
|
|
|
-
|
|
|
+ /** 全部播完回调 */
|
|
|
public completeCallback: Function;
|
|
|
-
|
|
|
+ /** 每帧回调 */
|
|
|
public frameCallback: Function;
|
|
|
-
|
|
|
+ /** 当前轮播次数 */
|
|
|
private currentTimes: number = 0;
|
|
|
|
|
|
onLoad() {
|
|
|
- this.m_render = this.getComponent(cc.Sprite);
|
|
|
+ this.comp_spr = this.getComponent(cc.Sprite);
|
|
|
}
|
|
|
|
|
|
start() {
|
|
|
@@ -107,10 +111,10 @@ export default class FrameAnimation extends cc.Component {
|
|
|
}
|
|
|
/** 播放中 */
|
|
|
private playing() {
|
|
|
- this.m_render.spriteFrame = this.images[this.frameIndex];
|
|
|
+ this.comp_spr.spriteFrame = this.images[this.frameIndex];
|
|
|
|
|
|
- if (this.m_render.spriteFrame) {
|
|
|
- var rect: cc.Rect = this.m_render.spriteFrame.getRect();
|
|
|
+ if (this.comp_spr.spriteFrame) {
|
|
|
+ var rect: cc.Rect = this.comp_spr.spriteFrame.getRect();
|
|
|
this.node.width = rect.width;
|
|
|
this.node.height = rect.height;
|
|
|
}
|
|
|
@@ -142,7 +146,9 @@ export default class FrameAnimation extends cc.Component {
|
|
|
if (this.autoDestroy && !CC_EDITOR) {
|
|
|
this.node.destroy();
|
|
|
}
|
|
|
- // this._edit_play = false;
|
|
|
+ // this.edit_play = false;
|
|
|
+ this._edit_play = false;
|
|
|
+ this.edit_playing = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -172,16 +178,16 @@ export default class FrameAnimation extends cc.Component {
|
|
|
|
|
|
}
|
|
|
|
|
|
- if (!this.m_render) {
|
|
|
- this.m_render = this.getComponent(cc.Sprite);
|
|
|
+ if (!this.comp_spr) {
|
|
|
+ this.comp_spr = this.getComponent(cc.Sprite);
|
|
|
}
|
|
|
|
|
|
- if (this.m_render)
|
|
|
- this.m_render.spriteFrame = this.images[0];
|
|
|
+ if (this.comp_spr)
|
|
|
+ this.comp_spr.spriteFrame = this.images[0];
|
|
|
|
|
|
|
|
|
- if (this.m_render.spriteFrame) {
|
|
|
- var rect: cc.Rect = this.m_render.spriteFrame.getRect();
|
|
|
+ if (this.comp_spr.spriteFrame) {
|
|
|
+ var rect: cc.Rect = this.comp_spr.spriteFrame.getRect();
|
|
|
this.node.width = rect.width;
|
|
|
this.node.height = rect.height;
|
|
|
}
|
|
|
@@ -193,8 +199,8 @@ export default class FrameAnimation extends cc.Component {
|
|
|
* @param frameIndex 帧下标
|
|
|
*/
|
|
|
public gotoAndPlay(frameIndex: number) {
|
|
|
- if (!this.m_render) {
|
|
|
- this.m_render = this.getComponent(cc.Sprite);
|
|
|
+ if (!this.comp_spr) {
|
|
|
+ this.comp_spr = this.getComponent(cc.Sprite);
|
|
|
}
|
|
|
|
|
|
this.running = true;
|
|
|
@@ -221,14 +227,14 @@ export default class FrameAnimation extends cc.Component {
|
|
|
if (this.frameIndex > this.images.length - 1)
|
|
|
this.frameIndex = this.images.length - 1;
|
|
|
|
|
|
- if (!this.m_render) {
|
|
|
- this.m_render = this.getComponent(cc.Sprite);
|
|
|
+ if (!this.comp_spr) {
|
|
|
+ this.comp_spr = this.getComponent(cc.Sprite);
|
|
|
}
|
|
|
|
|
|
- this.m_render.spriteFrame = this.images[this.frameIndex];
|
|
|
+ this.comp_spr.spriteFrame = this.images[this.frameIndex];
|
|
|
|
|
|
- if (this.m_render.spriteFrame) {
|
|
|
- var rect: cc.Rect = this.m_render.spriteFrame.getRect();
|
|
|
+ if (this.comp_spr.spriteFrame) {
|
|
|
+ var rect: cc.Rect = this.comp_spr.spriteFrame.getRect();
|
|
|
this.node.width = rect.width;
|
|
|
this.node.height = rect.height;
|
|
|
}
|