should ignore animation playOnLoad if already play an animation

This commit is contained in:
2youyouo2
2017-08-29 17:58:07 +08:00
parent 6b7cd8d1a2
commit 6bc0ff1cae
2 changed files with 34 additions and 1 deletions
+2 -1
View File
@@ -169,7 +169,8 @@ var Animation = cc.Class({
},
start: function () {
if (!CC_EDITOR && this.playOnLoad && this._defaultClip) {
var isPlaying = this._animator && this._animator.isPlaying;
if (!CC_EDITOR && !isPlaying && this.playOnLoad && this._defaultClip) {
var state = this.getAnimationState(this._defaultClip.name);
this._animator.playState(state);
}
+32
View File
@@ -1553,3 +1553,35 @@ test('animation pause/resume should remove animation-actor from animation manage
strictEqual(manager._animators.array.length, 0, 'should remove animation from animation manager');
});
test('animation play on load', function () {
var entity = new cc.Node();
var animation = entity.addComponent(cc.Animation);
animation.playOnLoad = true;
var clip1 = new cc.AnimationClip();
clip1._name = 'clip1';
clip1._duration = 1;
var clip2 = new cc.AnimationClip();
clip2._name = 'clip2';
clip2._duration = 1;
animation.addClip(clip1);
animation.addClip(clip2);
animation._defaultClip = clip1;
animation.play('clip2');
entity.parent = cc.director.getScene();
animation.start();
strictEqual(animation.getAnimationState('clip1').isPlaying, false, 'default clip should not be played if there is playing animation');
strictEqual(animation.getAnimationState('clip2').isPlaying, true, 'should play the specified animation');
entity.parent = null;
});