فهرست منبع

Merge pull request #1402 from AGallouin/master

Kill only one animation on a object
David Catuhe 8 سال پیش
والد
کامیت
e7d6ec8302
4فایلهای تغییر یافته به همراه4297 افزوده شده و 4285 حذف شده
  1. 4277 4276
      dist/preview release/babylon.d.ts
  2. 2 0
      dist/preview release/what's new.md
  3. 14 6
      src/Animations/babylon.animatable.ts
  4. 4 3
      src/babylon.scene.ts

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 4277 - 4276
dist/preview release/babylon.d.ts


+ 2 - 0
dist/preview release/what's new.md

@@ -29,6 +29,8 @@
  - New property in Canvas2D (instances) that contains all instances of canvas2d [Temechon](https://github.com/Temechon)
 - WebVR Camera was updated to be conform with the current specs. ([RaananW](https://github.com/RaananW)) 
 - New "CubeTextureTask" function will allow you to load a CubeTexture in the assetsManager. ([agallouin](https://github.com/AGallouin)) 
+- Scene.stopAnimation has now an optional second parameter, the name of the animation to kill.
+Usefull if a mesh has multiple animations. ([agallouin](https://github.com/AGallouin)) 
 
 ### Exporters
     

+ 14 - 6
src/Animations/babylon.animatable.ts

@@ -90,19 +90,27 @@
             this._paused = false;
         }
 
-        public stop(): void {
+        public stop(animationName?: string): void {
             var index = this._scene._activeAnimatables.indexOf(this);
 
             if (index > -1) {
-                this._scene._activeAnimatables.splice(index, 1);
-
                 var animations = this._animations;
-                for (var index = 0; index < animations.length; index++) {
+                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 ++;
                 }
 
-                if (this.onAnimationEnd) {
-                    this.onAnimationEnd();
+                if (animations.length == numberOfAnimationsStopped) {
+                    this._scene._activeAnimatables.splice(index, 1);
+
+                    if (this.onAnimationEnd) {
+                        this.onAnimationEnd();
+                    }
                 }
             }
         }

+ 4 - 3
src/babylon.scene.ts

@@ -1189,13 +1189,14 @@
         /**
          * Will stop the animation of the given target
          * @param target - the target 
-         * @see beginAnimation 
+         * @param animationName - the name of the animation to stop (all animations will be stopped is empty)
+         * @see beginAnimation
          */
-        public stopAnimation(target: any): void {
+        public stopAnimation(target: any, animationName?: string): void {
             var animatable = this.getAnimatableByTarget(target);
 
             if (animatable) {
-                animatable.stop();
+                animatable.stop(animationName);
             }
         }