ncannasse 8 vuotta sitten
vanhempi
commit
71d6699b60
1 muutettua tiedostoa jossa 8 lisäystä ja 0 poistoa
  1. 8 0
      h2d/Tile.hx

+ 8 - 0
h2d/Tile.hx

@@ -153,6 +153,14 @@ class Tile {
 		return [for( y in 0...Std.int(height / size) ) for( x in 0...Std.int(width / size) ) sub(x * size, y * size, size, size, dx, dy)];
 		return [for( y in 0...Std.int(height / size) ) for( x in 0...Std.int(width / size) ) sub(x * size, y * size, size, size, dx, dy)];
 	}
 	}
 
 
+	/**
+		Split the tile into a list of tiles of Size x Size pixels.
+		Unly grid which is Y/X ordered, grid2D returns an X/Y two-dimensional array.
+	**/
+	public function grid2D( size : Int, dx = 0, dy = 0 ) {
+		return [for( x in 0...Std.int(width / size) ) [for( y in 0...Std.int(height / size) ) sub(x * size, y * size, size, size, dx, dy)]];
+	}
+
 	public function toString() {
 	public function toString() {
 		return "Tile(" + x + "," + y + "," + width + "x" + height + (dx != 0 || dy != 0 ? "," + dx + ":" + dy:"") + ")";
 		return "Tile(" + x + "," + y + "," + width + "x" + height + (dx != 0 || dy != 0 ? "," + dx + ":" + dy:"") + ")";
 	}
 	}