Преглед изворни кода

onAnimationEnd for sprite.playAnimation

David Catuhe пре 9 година
родитељ
комит
dcdb8120a8

Разлика између датотеке није приказан због своје велике величине
+ 5 - 5
dist/preview release/babylon.core.js


Разлика између датотеке није приказан због своје велике величине
+ 2353 - 2352
dist/preview release/babylon.d.ts


Разлика између датотеке није приказан због своје велике величине
+ 5 - 5
dist/preview release/babylon.js


+ 6 - 2
dist/preview release/babylon.max.js

@@ -26926,7 +26926,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
-        Sprite.prototype.playAnimation = function (from, to, loop, delay) {
+        Sprite.prototype.playAnimation = function (from, to, loop, delay, onAnimationEnd) {
             this._fromIndex = from;
             this._toIndex = to;
             this._loopAnimation = loop;
@@ -26935,6 +26935,7 @@ var BABYLON;
             this._direction = from < to ? 1 : -1;
             this.cellIndex = from;
             this._time = 0;
+            this._onAnimationEnd = onAnimationEnd;
         };
         Sprite.prototype.stopAnimation = function () {
             this._animationStarted = false;
@@ -26946,12 +26947,15 @@ var BABYLON;
             if (this._time > this._delay) {
                 this._time = this._time % this._delay;
                 this.cellIndex += this._direction;
-                if (this.cellIndex == this._toIndex) {
+                if (this.cellIndex === this._toIndex) {
                     if (this._loopAnimation) {
                         this.cellIndex = this._fromIndex;
                     }
                     else {
                         this._animationStarted = false;
+                        if (this._onAnimationEnd) {
+                            this._onAnimationEnd();
+                        }
                         if (this.disposeWhenFinishedAnimating) {
                             this.dispose();
                         }

Разлика између датотеке није приказан због своје велике величине
+ 5 - 5
dist/preview release/babylon.noworker.js


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

@@ -3,6 +3,7 @@
 ### Major updates
     
 ### Updates
+- Added onAnimationEnd callback for `sprite.playAnimation` ([deltakosh](https://github.com/deltakosh)) 
 - Added support for non square textures for sprites ([deltakosh](https://github.com/deltakosh)) 
 - Added support for texture arrays ([deltakosh](https://github.com/deltakosh)) 
 - Added `camera.isInFrustum` and `camera.isCompletelyInFrustum`. Can be used with meshes, submeshes and boundingInfo ([deltakosh](https://github.com/deltakosh)) 

+ 6 - 2
src/Sprites/babylon.sprite.js

@@ -35,7 +35,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
-        Sprite.prototype.playAnimation = function (from, to, loop, delay) {
+        Sprite.prototype.playAnimation = function (from, to, loop, delay, onAnimationEnd) {
             this._fromIndex = from;
             this._toIndex = to;
             this._loopAnimation = loop;
@@ -44,6 +44,7 @@ var BABYLON;
             this._direction = from < to ? 1 : -1;
             this.cellIndex = from;
             this._time = 0;
+            this._onAnimationEnd = onAnimationEnd;
         };
         Sprite.prototype.stopAnimation = function () {
             this._animationStarted = false;
@@ -55,12 +56,15 @@ var BABYLON;
             if (this._time > this._delay) {
                 this._time = this._time % this._delay;
                 this.cellIndex += this._direction;
-                if (this.cellIndex == this._toIndex) {
+                if (this.cellIndex === this._toIndex) {
                     if (this._loopAnimation) {
                         this.cellIndex = this._fromIndex;
                     }
                     else {
                         this._animationStarted = false;
+                        if (this._onAnimationEnd) {
+                            this._onAnimationEnd();
+                        }
                         if (this.disposeWhenFinishedAnimating) {
                             this.dispose();
                         }

+ 8 - 2
src/Sprites/babylon.sprite.ts

@@ -22,6 +22,7 @@
         private _frameCount = 0;
         private _manager: SpriteManager;
         private _time = 0;
+        private _onAnimationEnd: () => void;
 
         public get size(): number {
             return this.width;
@@ -40,7 +41,7 @@
             this.position = Vector3.Zero();
         }
 
-        public playAnimation(from: number, to: number, loop: boolean, delay: number): void {
+        public playAnimation(from: number, to: number, loop: boolean, delay: number, onAnimationEnd: () => void): void {
             this._fromIndex = from;
             this._toIndex = to;
             this._loopAnimation = loop;
@@ -51,6 +52,8 @@
 
             this.cellIndex = from;
             this._time = 0;
+
+            this._onAnimationEnd = onAnimationEnd;
         }
 
         public stopAnimation(): void {
@@ -65,11 +68,14 @@
             if (this._time > this._delay) {
                 this._time = this._time % this._delay;
                 this.cellIndex += this._direction;
-                if (this.cellIndex == this._toIndex) {
+                if (this.cellIndex === this._toIndex) {
                     if (this._loopAnimation) {
                         this.cellIndex = this._fromIndex;
                     } else {
                         this._animationStarted = false;
+                        if (this._onAnimationEnd) {
+                            this._onAnimationEnd();
+                        }
                         if (this.disposeWhenFinishedAnimating) {
                             this.dispose();
                         }