Merge pull request #1941 from 2youyou2/v1.6

should ignore animation playOnLoad if already play an animation
This commit is contained in:
Jare Guo
2017-08-29 18:19:08 +08:00
committed by GitHub
2 changed files with 37 additions and 2 deletions
+5 -2
View File
@@ -170,8 +170,11 @@ var Animation = cc.Class({
start: function () {
if (!CC_EDITOR && this.playOnLoad && this._defaultClip) {
var state = this.getAnimationState(this._defaultClip.name);
this._animator.playState(state);
var isPlaying = this._animator && this._animator.isPlaying;
if (!isPlaying) {
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;
});