private static void DrawCollisionLayer(SKCanvas canvas, TmxLayer tmxLayer, SKColor polyColor, SKColor lineColor) { LayerClipper.TransformPointFunc xfFunc = (x, y) => new ClipperLib.IntPoint(x, y); LayerClipper.ProgressFunc progFunc = (prog) => { }; // do nothing ClipperLib.PolyTree solution = LayerClipper.ExecuteClipper(tmxLayer.TmxMap, tmxLayer, xfFunc, progFunc); using (SKPaint paint = new SKPaint()) { // Draw all closed polygons // First, add them to the path // (But are we using convex polygons are complex polygons? using (SKPath path = new SKPath()) { var polygons = tmxLayer.IsExportingConvexPolygons() ? LayerClipper.SolutionPolygons_Simple(solution) : LayerClipper.SolutionPolygons_Complex(solution); foreach (var pointfArray in polygons) { var pts = pointfArray.ToSkPointArray(); path.AddPoly(pts, true); } // Then, fill and draw the path full of polygons if (path.PointCount > 0) { paint.Style = SKPaintStyle.Fill; paint.Color = polyColor; canvas.DrawPath(path, paint); paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = StrokeWidthThick; paint.Color = lineColor; canvas.DrawPath(path, paint); } } // Draw all lines (open polygons) using (SKPath path = new SKPath()) { foreach (var points in ClipperLib.Clipper.OpenPathsFromPolyTree(solution)) { var pts = points.Select(pt => new SKPoint(pt.X, pt.Y)).ToArray(); path.AddPoly(pts, false); } if (path.PointCount > 0) { paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = StrokeWidthThick; paint.Color = lineColor; canvas.DrawPath(path, paint); } } } }
private static void DrawLayerColliders(Graphics g, TmxLayer tmxLayer, Color polyColor, Color lineColor, float scale) { LayerClipper.TransformPointFunc xfFunc = (x, y) => new ClipperLib.IntPoint(x, y); LayerClipper.ProgressFunc progFunc = (prog) => { }; // do nothing ClipperLib.PolyTree solution = LayerClipper.ExecuteClipper(tmxLayer.TmxMap, tmxLayer, xfFunc, progFunc); float inverseScale = 1.0f / scale; if (inverseScale > 1) { inverseScale = 1; } using (GraphicsPath path = new GraphicsPath()) using (Pen pen = new Pen(lineColor, 2.0f * inverseScale)) using (Brush brush = TmxHelper.CreateLayerColliderBrush(polyColor)) { // Draw all closed polygons // First, add them to the path // (But are we using convex polygons are complex polygons? var polygons = tmxLayer.IsExportingConvexPolygons() ? LayerClipper.SolutionPolygons_Simple(solution) : LayerClipper.SolutionPolygons_Complex(solution); foreach (var pointfArray in polygons) { path.AddPolygon(pointfArray); } // Then, fill and draw the path full of polygons if (path.PointCount > 0) { g.FillPath(brush, path); g.DrawPath(pen, path); } // Draw all lines (open polygons) path.Reset(); foreach (var points in ClipperLib.Clipper.OpenPathsFromPolyTree(solution)) { var pointfs = points.Select(pt => new PointF(pt.X, pt.Y)); path.StartFigure(); path.AddLines(pointfs.ToArray()); } if (path.PointCount > 0) { g.DrawPath(pen, path); } } }