public static List <PointF> GetPointsInMapSpace(TmxMap tmxMap, TmxHasPoints objectWithPoints) { PointF local = ObjectPointFToMapSpace(tmxMap, 0f, 0f); local.X = 0f - local.X; local.Y = 0f - local.Y; return((from pt in (from pt in objectWithPoints.Points select ObjectPointFToMapSpace(tmxMap, pt)).ToList() select AddPoints(pt, local)).ToList()); }
public static List<PointF> GetPointsInMapSpace(TmxMap tmxMap, TmxHasPoints objectWithPoints) { PointF local = TmxMath.ObjectPointFToMapSpace(tmxMap, 0, 0); local.X = -local.X; local.Y = -local.Y; List<PointF> xfPoints = objectWithPoints.Points.Select(pt => TmxMath.ObjectPointFToMapSpace(tmxMap, pt)).ToList(); xfPoints = xfPoints.Select(pt => TmxMath.AddPoints(pt, local)).ToList(); return xfPoints; }
public static List <PointF> GetPointsInMapSpace(TmxMap tmxMap, TmxHasPoints objectWithPoints) { PointF local = TmxMath.ObjectPointFToMapSpace(tmxMap, 0, 0); local.X = -local.X; local.Y = -local.Y; List <PointF> xfPoints = objectWithPoints.Points.Select(pt => TmxMath.ObjectPointFToMapSpace(tmxMap, pt)).ToList(); xfPoints = xfPoints.Select(pt => TmxMath.AddPoints(pt, local)).ToList(); return(xfPoints); }
private void FixTileColliderObjects(TmxMap tmxMap) { // Objects inside of tiles are colliders that will be merged with the colliders on neighboring tiles. // In order to promote this merging we have to perform the following clean up operations ... // - All rectangles objects are made into polygon objects // - All polygon objects will have their rotations burned into the polygon points (and Rotation set to zero) // - All cooridinates will be "sanitized" to make up for floating point errors due to rotation and poor placement of colliders // (The sanitation will round all numbers to the nearest 1/256th) // Replace rectangles with polygons for (int i = 0; i < this.ObjectGroup.Objects.Count; i++) { TmxObject tmxObject = this.ObjectGroup.Objects[i]; if (tmxObject is TmxObjectRectangle) { TmxObjectPolygon tmxObjectPolygon = TmxObjectPolygon.FromRectangle(tmxMap, tmxObject as TmxObjectRectangle); this.ObjectGroup.Objects[i] = tmxObjectPolygon; } } // Burn rotation into all polygon points, sanitizing the point locations as we go foreach (TmxObject tmxObject in this.ObjectGroup.Objects) { TmxHasPoints tmxHasPoints = tmxObject as TmxHasPoints; if (tmxHasPoints != null) { var pointfs = tmxHasPoints.Points.ToArray(); // Rotate our points by the rotation and position in the object TmxMath.RotatePoints(pointfs, tmxObject); // Sanitize our points to make up for floating point precision errors pointfs = pointfs.Select(TmxMath.Sanitize).ToArray(); // Set the points back into the object tmxHasPoints.Points = pointfs.ToList(); // Zero out our rotation tmxObject.BakeRotation(); } } }
private void FixTileColliderObjects(TmxMap tmxMap) { for (int i = 0; i < ObjectGroup.Objects.Count; i++) { TmxObject tmxObject = ObjectGroup.Objects[i]; if (tmxObject is TmxObjectRectangle) { TmxObjectPolygon value = TmxObjectPolygon.FromRectangle(tmxMap, tmxObject as TmxObjectRectangle); ObjectGroup.Objects[i] = value; } } foreach (TmxObject @object in ObjectGroup.Objects) { TmxHasPoints tmxHasPoints = @object as TmxHasPoints; if (tmxHasPoints != null) { PointF[] array = tmxHasPoints.Points.ToArray(); TmxMath.RotatePoints(array, @object); array = array.Select(TmxMath.Sanitize).ToArray(); tmxHasPoints.Points = array.ToList(); @object.BakeRotation(); } } }