Browse Source

Merge pull request #1275 from nockawa/master

Fixing Sprite Texture loading delay and Primitive not added to Dirty …
David Catuhe 9 years ago
parent
commit
09fa241d5b

+ 5 - 10
src/Canvas2d/babylon.prim2dBase.ts

@@ -2440,8 +2440,9 @@
         }
 
         protected onPrimBecomesDirty() {
-            if (this._renderGroup) {
+            if (this._renderGroup && !this._isFlagSet(SmartPropertyPrim.flagPrimInDirtyList)) {
                 this._renderGroup._addPrimToDirtyList(this);
+                this._setFlags(SmartPropertyPrim.flagPrimInDirtyList);
             }
         }
 
@@ -2512,9 +2513,7 @@
         }
 
         protected _setLayoutDirty() {
-            if (!this.isDirty) {
-                this.onPrimBecomesDirty();
-            }
+            this.onPrimBecomesDirty();
             this._setFlags(SmartPropertyPrim.flagLayoutDirty);
 
         }
@@ -2528,9 +2527,7 @@
         }
 
         protected _positioningDirty() {
-            if (!this.isDirty) {
-                this.onPrimBecomesDirty();
-            }
+            this.onPrimBecomesDirty();
             this._setFlags(SmartPropertyPrim.flagPositioningDirty);
         }
 
@@ -2976,9 +2973,7 @@
         private _setZOrder(newZ: number, directEmit: boolean) {
             if (newZ !== this._zOrder) {
                 this._zOrder = newZ;
-                if (!this.isDirty) {
-                    this.onPrimBecomesDirty();
-                }
+                this.onPrimBecomesDirty();
                 this.onZOrderChanged();
                 if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
                     if (directEmit) {

+ 3 - 3
src/Canvas2d/babylon.smartPropertyPrim.ts

@@ -411,9 +411,7 @@
         }
 
         protected onPrimitivePropertyDirty(propFlagId: number) {
-            if (!this.isDirty) {
-                this.onPrimBecomesDirty();
-            }
+            this.onPrimBecomesDirty();
             this._instanceDirtyFlags |= propFlagId;
         }
 
@@ -442,6 +440,7 @@
 
         public _resetPropertiesDirty() {
             this._instanceDirtyFlags = 0;
+            this._clearFlags(SmartPropertyPrim.flagPrimInDirtyList);
         }
 
         /**
@@ -629,6 +628,7 @@
         public static flagChildrenFlatZOrder     = 0x0001000;    // set if all the children (direct and indirect) will share the same Z-Order
         public static flagZOrderDirty            = 0x0002000;    // set if the Z-Order for this prim and its children must be recomputed
         public static flagActualOpacityDirty     = 0x0004000;    // set if the actualOpactity should be recomputed
+        public static flagPrimInDirtyList        = 0x0008000;    // set if the primitive is in the primDirtyList
 
         private   _flags             : number;
         private   _externalData      : StringDictionary<Object>;

+ 4 - 2
src/Canvas2d/babylon.sprite2d.ts

@@ -311,12 +311,14 @@
             this.alignToPixel = (settings.alignToPixel == null) ? true : settings.alignToPixel;
             this.isAlphaTest = true;
 
-            if (settings.spriteSize == null) {
+            if (settings.spriteSize == null || !texture.isReady()) {
                 if (texture.isReady()) {
                     this.size = <Size>texture.getSize();
                 } else {
                     texture.onLoadObservable.add(() => {
-                        this.size = <Size>texture.getSize();
+                        if (settings.spriteSize == null) {
+                            this.size = <Size>texture.getSize();
+                        }
                         this._positioningDirty();
                     });
                 }