소스 검색

Fix animationGroup loop mode control

David Catuhe 6 년 전
부모
커밋
9875c77698
1개의 변경된 파일24개의 추가작업 그리고 4개의 파일을 삭제
  1. 24 4
      src/Animations/animationGroup.ts

+ 24 - 4
src/Animations/animationGroup.ts

@@ -33,6 +33,7 @@ export class AnimationGroup implements IDisposable {
     private _isStarted: boolean;
     private _isPaused: boolean;
     private _speedRatio = 1;
+    private _loopAnimation = false;
 
     /**
      * Gets or sets the unique id of the node
@@ -116,6 +117,26 @@ export class AnimationGroup implements IDisposable {
     }
 
     /**
+     * Gets or sets if all animations should loop or not
+     */
+    public get loopAnimation(): boolean {
+        return this._loopAnimation;
+    }
+
+    public set loopAnimation(value: boolean) {
+        if (this._loopAnimation === value) {
+            return;
+        }
+
+        this._loopAnimation = value;
+
+        for (var index = 0; index < this._animatables.length; index++) {
+            let animatable = this._animatables[index];
+            animatable.loopAnimation = this._loopAnimation;
+        }
+    }
+
+    /**
      * Gets the targeted animations for this animation group
      */
     public get targetedAnimations(): Array<TargetedAnimation> {
@@ -231,6 +252,8 @@ export class AnimationGroup implements IDisposable {
             return this;
         }
 
+        this._loopAnimation = loop;
+
         for (const targetedAnimation of this._targetedAnimations) {
             let animatable = this._scene.beginDirectAnimation(targetedAnimation.target, [targetedAnimation.animation], from !== undefined ? from : this._from, to !== undefined ? to : this._to, loop, speedRatio);
             animatable.onAnimationEnd = () => {
@@ -294,10 +317,7 @@ export class AnimationGroup implements IDisposable {
         // only if all animatables are ready and exist
         if (this.isStarted && this._animatables.length === this._targetedAnimations.length) {
             if (loop !== undefined) {
-                for (var index = 0; index < this._animatables.length; index++) {
-                    let animatable = this._animatables[index];
-                    animatable.loopAnimation = loop;
-                }
+                this.loopAnimation = loop;
             }
             this.restart();
         } else {