diff --git a/MLEM.Extended/Tiled/TiledExtensions.cs b/MLEM.Extended/Tiled/TiledExtensions.cs index f4915fc..edd08e1 100644 --- a/MLEM.Extended/Tiled/TiledExtensions.cs +++ b/MLEM.Extended/Tiled/TiledExtensions.cs @@ -58,7 +58,7 @@ namespace MLEM.Extended.Tiled { } public static TiledMapTile GetTile(this TiledMapTileLayer layer, int x, int y) { - return layer.GetTile((ushort) x, (ushort) y); + return !layer.IsInBounds(x, y) ? default : layer.GetTile((ushort) x, (ushort) y); } public static RectangleF GetArea(this TiledMapObject obj, TiledMap map, Vector2? position = null) { @@ -71,5 +71,9 @@ namespace MLEM.Extended.Tiled { return new Vector2(map.TileWidth, map.TileHeight); } + public static bool IsInBounds(this TiledMapTileLayer layer, int x, int y) { + return x >= 0 && y >= 0 && x < layer.Width && y < layer.Height; + } + } } \ No newline at end of file