diff --git a/MLEM.Extended/Tiled/TiledMapCollisions.cs b/MLEM.Extended/Tiled/TiledMapCollisions.cs index c5daa76..84ff91c 100644 --- a/MLEM.Extended/Tiled/TiledMapCollisions.cs +++ b/MLEM.Extended/Tiled/TiledMapCollisions.cs @@ -43,9 +43,13 @@ namespace MLEM.Extended.Tiled { public IEnumerable GetCollidingTiles(RectangleF area, Func included = null) { var inclusionFunc = included ?? (tile => tile.Collisions.Any(c => c.Intersects(area))); + var minX = Math.Max(0, area.Left.Floor()); + var maxX = Math.Min(this.map.Width - 1, area.Right); + var minY = Math.Max(0, area.Top.Floor()); + var maxY = Math.Min(this.map.Height - 1, area.Bottom); for (var i = 0; i < this.map.TileLayers.Count; i++) { - for (var x = area.Left.Floor(); x <= area.Right; x++) { - for (var y = area.Top.Floor(); y <= area.Bottom; y++) { + for (var x = minX; x <= maxX; x++) { + for (var y = minY; y <= maxY; y++) { var tile = this.collisionInfos[i, x, y]; if (tile == null) continue;