From 9e8e43c2ff7ccf8de49f62b48c764c7b40ac8faa Mon Sep 17 00:00:00 2001 From: PP Date: Tue, 29 May 2018 10:02:02 +0800 Subject: [PATCH] pause animation playing when unenabled (#2718) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add animation warn id fix animation bug 添加注释 英文注释 --- cocos2d/core/components/CCAnimation.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index a0e7d47a21..95c1fc4674 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -262,6 +262,14 @@ var Animation = cc.Class({ animator.playState(state, startTime); } + // Animation cannot be played when the component is not enabledInHierarchy. + // That would cause an error for the animation lost the reference after destroying the node. + // If users play the animation when the component is not enabledInHierarchy, + // we pause the animator here so that it will automatically resume the animation when users enable the component. + if (!this.enabledInHierarchy) { + animator.pause(); + } + this.currentClip = state.clip; } return state;