private static void DrawGridQuad(SKCanvas canvas, TmxMap tmxMap) { HashSet <Point> points = new HashSet <Point>(); for (int x = 0; x < GetMaxTilesWide(tmxMap); ++x) { for (int y = 0; y < GetMaxTilesHigh(tmxMap); ++y) { // Add the "top-left" corner of a tile points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y)); // Add all other corners of the tile to our list of grid points // This is complicated by different map types (espcially staggered isometric) if (tmxMap.Orientation == TmxMap.MapOrientation.Orthogonal || tmxMap.Orientation == TmxMap.MapOrientation.Isometric) { points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x + 1, y)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x + 1, y + 1)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y + 1)); } else if (tmxMap.Orientation == TmxMap.MapOrientation.Staggered) { bool sx = TmxMath.DoStaggerX(tmxMap, x); bool sy = TmxMath.DoStaggerY(tmxMap, y); if (sx) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x + 1, y + 1)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y + 1)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x - 1, y + 1)); } else if (sy) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x + 1, y + 1)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y + 2)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y + 1)); } else if (tmxMap.StaggerAxis == TmxMap.MapStaggerAxis.X) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x + 1, y)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y + 1)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x - 1, y)); } else if (tmxMap.StaggerAxis == TmxMap.MapStaggerAxis.Y) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y + 1)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x, y + 2)); points.Add(TmxMath.TileCornerFromGridCoordinates(tmxMap, x - 1, y + 1)); } } } } // Can take for granted that background is always white in drawing black rectangles using (SKPaint paint = new SKPaint()) { paint.Color = SKColors.Black; paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = StrokeWidthThin; foreach (var p in points) { SKRect rc = SKRect.Create(p.X, p.Y, PreviewImage.GridSize, PreviewImage.GridSize); rc.Offset(-PreviewImage.GridSize * 0.5f, -PreviewImage.GridSize * 0.5f); canvas.DrawRect(rc, paint); } } }