소스 검색

bugfix: scalegrid was not getting updated when tile changed

ncannasse 6 년 전
부모
커밋
161c7349c8
1개의 변경된 파일12개의 추가작업 그리고 5개의 파일을 삭제
  1. 12 5
      h2d/ScaleGrid.hx

+ 12 - 5
h2d/ScaleGrid.hx

@@ -11,6 +11,8 @@ class ScaleGrid extends h2d.TileGroup {
 
 	public var tileBorders(default, set) : Bool;
 
+	var contentTile : h2d.Tile;
+
 	public function new( tile, borderW, borderH, ?parent ) {
 		super(tile,parent);
 		borderWidth = borderW;
@@ -55,10 +57,18 @@ class ScaleGrid extends h2d.TileGroup {
 	}
 
 	override function getBoundsRec(relativeTo, out, forSize) {
-		if( content.isEmpty() ) updateContent();
+		checkUpdate();
 		super.getBoundsRec(relativeTo, out, forSize);
 	}
 
+	function checkUpdate() {
+		if( content.isEmpty() || tile != contentTile ) {
+			clear();
+			contentTile = tile;
+			updateContent();
+		}
+	}
+
 	function updateContent() {
 		var bw = borderWidth, bh = borderHeight;
 
@@ -123,10 +133,7 @@ class ScaleGrid extends h2d.TileGroup {
 	}
 
 	override function sync( ctx : RenderContext ) {
-		if( content.isEmpty() ) {
-			content.dispose();
-			updateContent();
-		}
+		checkUpdate();
 		super.sync(ctx);
 	}