Bläddra i källkod

Fixed issue with getData() callback

Borut 7 år sedan
förälder
incheckning
1ab1acc6cd
2 ändrade filer med 7440 tillägg och 7444 borttagningar
  1. 7431 7429
      dist/preview release/babylon.d.ts
  2. 9 15
      src/Physics/babylon.physicsHelper.ts

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 7431 - 7429
dist/preview release/babylon.d.ts


+ 9 - 15
src/Physics/babylon.physicsHelper.ts

@@ -276,7 +276,7 @@ module BABYLON {
         private _falloff: PhysicsRadialImpulseFallof;
         private _tickCallback: any;
         private _radialSphere: Mesh;
-        private _dataRequested: boolean = false; // check if the has been requested the data. If not, do cleanup
+        private _dataFetched: boolean = false; // check if the has been fetched the data. If not, do cleanup
 
         constructor(
             physicsHelper: PhysicsHelper,
@@ -295,22 +295,16 @@ module BABYLON {
             this._tickCallback = this._tick.bind(this);
         }
 
-        public getData(callback: (data: PhysicsGravitationalFieldEventData) => void) {
-            this._dataRequested = true;
-
-            var self = this;
-            // wait until the first tick has ran, so we can the the radialExplosionEvent (& it's data)
-            var interval = setInterval(function() {
-                if (self._radialSphere) {
-                    clearInterval(interval);
-                    callback({
-                        radialSphere: self._radialSphere,
-                    });
-                }
-            }, 16.66);
+        public getData() {
+            this._dataFetched = true;
+
+            return {
+                radialSphere: this._radialSphere,
+            };
         }
 
         public enable() {
+            this._tickCallback.call(this);
             this._scene.registerBeforeRender(this._tickCallback);
         }
 
@@ -324,7 +318,7 @@ module BABYLON {
             } else {
                 var self = this;
                 setTimeout(function () {
-                    if (!self._dataRequested) {
+                    if (!self._dataFetched) {
                         self._radialSphere.dispose();
                     }
                 }, 0);