From cc18e4652c64e647fcf7183941118fcaa8f7afee Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Thu, 17 Mar 2016 16:03:06 +0800 Subject: [PATCH] fixed animation onEnable/onDisable --- cocos2d/core/components/CCAnimation.js | 6 ++++- test/qunit/unit/test-animation.js | 35 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index fe47e40078..f0091467cb 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -156,8 +156,12 @@ var Animation = cc.Class({ } }, + onEnable: function () { + this.resume(); + }, + onDisable: function () { - this.stop(); + this.pause(); }, /////////////////////////////////////////////////////////////////////////////// diff --git a/test/qunit/unit/test-animation.js b/test/qunit/unit/test-animation.js index f6ff512092..c8ed6bf5a6 100644 --- a/test/qunit/unit/test-animation.js +++ b/test/qunit/unit/test-animation.js @@ -1203,3 +1203,38 @@ test('play Animation', function () { strictEqual(moveState.isPlaying, false, 'move animation state should not be playing'); strictEqual(rotateState.isPlaying, false, 'rotate animation state should be playing'); }); + +test('animation enabled/disabled', function () { + var scene = cc.director.getScene(); + var entity = new cc.Node(); + var animation = entity.addComponent(cc.Animation); + + entity.parent = scene; + + var clip = new cc.AnimationClip(); + clip._name = 'move'; + clip._duration = 1; + clip.curveData = { + props: { + x: [ + {frame: 0, value: 0}, + {frame: 1, value: 100} + ] + } + }; + animation.addClip(clip); + animation.play('move'); + + animation.enabled = false; + + strictEqual(animation._animator.isPlaying, true, 'move animation should be playing'); + strictEqual(animation._animator.isPaused, true, 'move animation should be paused'); + + animation.enabled = true; + + strictEqual(animation._animator.isPlaying, true, 'move animation should be playing'); + strictEqual(animation._animator.isPaused, false, 'move animation should be resumed'); + + entity.parent = null; +}); +