Browse Source

fixed getBounds when not on scene (use new Sprite instead of top parent)

ncannasse 11 năm trước cách đây
mục cha
commit
1079bcc73b
1 tập tin đã thay đổi với 4 bổ sung8 xóa
  1. 4 8
      h2d/Sprite.hx

+ 4 - 8
h2d/Sprite.hx

@@ -41,6 +41,8 @@ class Sprite {
 		if( out == null ) out = new h2d.col.Bounds();
 		if( relativeTo == null ) {
 			relativeTo = getScene();
+			if( relativeTo == null )
+				relativeTo = new Sprite();
 		} else {
 			var s1 = getScene();
 			var s2 = relativeTo.getScene();
@@ -48,19 +50,13 @@ class Sprite {
 				// if we are getting the bounds relative to a scene
 				// were are not into, it's the same as taking absolute position
 				if( s1 == null && s2 == relativeTo )
-					relativeTo = null;
+					relativeTo = new Sprite();
 				else if( s2 == null )
 					throw "Cannot getBounds() with a relative element not in the scene";
 				else
 					throw "Cannot getBounds() with a relative element in a different scene";
 			}
-			if( relativeTo != null )
-				relativeTo.syncPos();
-		}
-		if( relativeTo == null ) {
-			relativeTo = this;
-			while( relativeTo.parent != null )
-				relativeTo = relativeTo.parent;
+			relativeTo.syncPos();
 		}
 		syncPos();
 		getBoundsRec(relativeTo, out);