Merge pull request #474 from 2youyouo2/anim

fixed animator stop
This commit is contained in:
Jare Guo
2016-03-14 15:22:27 +08:00
5 changed files with 29 additions and 16 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ p.setStateTime = function (state, time) {
p.onStop = function () {
var anims = this.playingAnims;
for (var i = 0, l = anims.length; i < l; i++) {
for (var i = anims.length - 1; i >= 0; i--) {
anims[i].stop();
}
+6
View File
@@ -65,6 +65,12 @@ state.onPlay = function () {
this.setTime(0);
};
state.onStop = function () {
if (this.animator) {
this.animator.removeAnimation(this);
}
};
state.setTime = function (time) {
this.time = time || 0;
+11 -6
View File
@@ -21,26 +21,32 @@ var animProto = Animator.prototype;
animProto.update = function (dt) {
this._updating = true;
var anims = this.playingAnims;
var i, l;
var anims = this.playingAnims;
var stoppedCount = 0;
for (i = 0, l = anims.length; i < l; i++) {
var anim = anims[i];
if (anim._isPlaying && !anim._isPaused) {
anim.update(dt);
if (!anim._isPlaying) {
stoppedCount ++;
}
}
}
this._updating = false;
if (anims.length === 0 || stoppedCount >= anims.length ) {
this.stop();
}
var removeList = this._removeList;
for (i = 0, l = removeList.length; i < l; i++) {
this.removeAnimation( removeList[i] );
}
removeList.length = 0;
if (anims.length === 0) {
this.stop();
}
};
animProto.onPlay = function () {
@@ -48,7 +54,6 @@ animProto.onPlay = function () {
};
animProto.onStop = function () {
this.playingAnims.length = 0;
cc.director.getAnimationManager().removeAnimator(this);
};
-9
View File
@@ -347,15 +347,6 @@ JS.mixin(AnimationNode.prototype, {
}
return info.stopped;
},
//onPlay: function () {
//},
onStop: function () {
if (this.animator) {
this.animator.removeAnimation(this);
}
}
});
+11
View File
@@ -1125,5 +1125,16 @@ test('stop Animation', function () {
strictEqual(animationManager.animators.length, 0, 'playing animators should be 0');
strictEqual(animation._animator.playingAnims.length, 0, 'playing anims should be 0');
animation.play('test');
animationManager.update(0.5);
strictEqual(animationManager.animators.length, 1, 'playing animators should be 1');
strictEqual(animation._animator.playingAnims.length, 1, 'playing anims should be 1');
animation.stop();
strictEqual(animationManager.animators.length, 0, 'playing animators should be 0');
strictEqual(animation._animator.playingAnims.length, 0, 'playing anims should be 0');
});