浏览代码

fixed all animations in scene stopping as a result of last fix

Adam Bowman 8 年之前
父节点
当前提交
0d095a20ca
共有 1 个文件被更改,包括 22 次插入15 次删除
  1. 22 15
      src/Animations/babylon.animatable.ts

+ 22 - 15
src/Animations/babylon.animatable.ts

@@ -99,26 +99,29 @@
         }
 
         public stop(animationName?: string): void {
-            var idx = this._scene._activeAnimatables.indexOf(this);
-
-            if (idx > -1) {
-
-                if(animationName){
+            
+            if (animationName) {
+                
+                var idx = this._scene._activeAnimatables.indexOf(this);
+                
+                if (idx) {
 
                     var animations = this._animations;
                     var numberOfAnimationsStopped = 0;
+
                     for (var index = animations.length - 1; index >= 0; index--) {
                         if (typeof animationName === "string" && animations[index].name != animationName) {
                             continue;
                         }
+
                         animations[index].reset();
                         animations.splice(index, 1);
-                        numberOfAnimationsStopped ++;
+                        numberOfAnimationsStopped++;
                     }
 
                     if (animations.length == numberOfAnimationsStopped) {
                         this._scene._activeAnimatables.splice(idx, 1);
-
+                        
                         if (this.onAnimationEnd) {
                             this.onAnimationEnd();
                         }
@@ -126,17 +129,21 @@
 
                 } else {
 
-                    this._scene._activeAnimatables.splice(index, 1);
-                    var animations = this._animations;
+                    var index = this._scene._activeAnimatables.indexOf(this);
 
-                    for (var index = 0; index < animations.length; index++) {
-                        animations[index].reset();
-                    }
+                    if (index > -1) {
+                        this._scene._activeAnimatables.splice(index, 1);
+                        var animations = this._animations;
+                        
+                        for (var index = 0; index < animations.length; index++) {
+                            animations[index].reset();
+                        }
 
-                    if (this.onAnimationEnd) {
-                        this.onAnimationEnd();
+                        if (this.onAnimationEnd) {
+                            this.onAnimationEnd();
+                        }
                     }
-
+                    
                 }
             }
         }