From b25b73ef6de575ea1b19a6b671b1784702c8edc6 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Tue, 22 Dec 2015 17:47:56 +0800 Subject: [PATCH] fixed animation may not play --- cocos2d/animation/animation-animator.js | 12 ++++++++---- cocos2d/core/components/CCAnimation.js | 23 +++++++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cocos2d/animation/animation-animator.js b/cocos2d/animation/animation-animator.js index 9c1f424bc9..9fdecf0ea9 100644 --- a/cocos2d/animation/animation-animator.js +++ b/cocos2d/animation/animation-animator.js @@ -18,17 +18,21 @@ JS.extend(AnimationAnimator, Animator); var p = AnimationAnimator.prototype; p.playState = function (state, startTime) { - var clip = state.clip; - if (!clip) { + if (!state.clip) { return; } - var curves = state.curves; + if (!state.curveLoaded) { initClipData(this.target, state); } + this.playingAnims.push(state); state.play(); - state.time = startTime || 0; + + if (typeof startTime === 'number') { + state.time = startTime; + } + this.play(); }; diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index 9ea5c1ff8c..6c121626a8 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -151,7 +151,6 @@ var Animation = cc.Class({ }, onDisable: function () { - this.setCurrentTime(0); this.stop(); }, @@ -179,17 +178,19 @@ var Animation = cc.Class({ this._init(); var state = this.getAnimationState(name || this._defaultClip.name); if (state) { - if (state.isPlaying) { + var animator = this._animator; + + if (animator.isPlaying && state.isPlaying) { if (state.isPaused) { - this._animator.resumeState(state); + animator.resumeState(state); } else { - this._animator.stopState(state); - this._animator.playState(state, startTime); + animator.stopState(state); + animator.playState(state, startTime); } } else { - this._animator.playState(state, startTime); + animator.playState(state, startTime); } this.currentClip = state.clip; @@ -412,6 +413,11 @@ var Animation = cc.Class({ var clip = this._clips[i]; if (clip) { state = new cc.AnimationState(clip); + + if (CC_EDITOR) { + this._animator.reloadClip(state); + } + this._nameToState[state.name] = state; if (equalClips(this._defaultClip, clip)) { defaultClipState = state; @@ -420,6 +426,11 @@ var Animation = cc.Class({ } if (this._defaultClip && !defaultClipState) { state = new cc.AnimationState(this._defaultClip); + + if (CC_EDITOR) { + this._animator.reloadClip(state); + } + this._nameToState[state.name] = state; } },