Browse Source

call removeChild when changing parent (allow Layers processing)

Nicolas Cannasse 13 năm trước cách đây
mục cha
commit
509cf5895e
1 tập tin đã thay đổi với 7 bổ sung2 xóa
  1. 7 2
      h2d/Sprite.hx

+ 7 - 2
h2d/Sprite.hx

@@ -64,8 +64,13 @@ class Sprite {
 			if( p == s ) throw "Recursive addChild";
 			p = p.parent;
 		}
-		if( s.parent != null )
-			s.parent.childs.remove(s);
+		if( s.parent != null ) {
+			// prevent calling onDelete
+			var old = s.allocated;
+			s.allocated = false;
+			s.parent.removeChild(s);
+			s.allocated = old;
+		}
 		childs.insert(pos,s);
 		s.parent = this;
 		s.posChanged = true;