{"id":30696050,"url":"https://github.com/thebonejarmer/tiledcs","last_synced_at":"2026-03-17T14:24:11.253Z","repository":{"id":41069211,"uuid":"326483461","full_name":"TheBoneJarmer/TiledCS","owner":"TheBoneJarmer","description":"TiledCS is a dotnet library for loading Tiled tilesets and maps","archived":false,"fork":false,"pushed_at":"2024-08-31T05:52:25.000Z","size":79,"stargazers_count":154,"open_issues_count":11,"forks_count":50,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-07-22T08:41:04.570Z","etag":null,"topics":["monogame","monogame-pipeline","tiled","tiled-map-editor","tiled-maps","tiled-parser","tmx","tmx-maps","tmx-parser"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheBoneJarmer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-01-03T19:20:14.000Z","updated_at":"2025-07-13T16:15:15.000Z","dependencies_parsed_at":"2024-03-09T21:47:04.161Z","dependency_job_id":null,"html_url":"https://github.com/TheBoneJarmer/TiledCS","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/TheBoneJarmer/TiledCS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBoneJarmer%2FTiledCS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBoneJarmer%2FTiledCS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBoneJarmer%2FTiledCS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBoneJarmer%2FTiledCS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheBoneJarmer","download_url":"https://codeload.github.com/TheBoneJarmer/TiledCS/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBoneJarmer%2FTiledCS/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273250283,"owners_count":25072167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["monogame","monogame-pipeline","tiled","tiled-map-editor","tiled-maps","tiled-parser","tmx","tmx-maps","tmx-parser"],"created_at":"2025-09-02T07:34:22.860Z","updated_at":"2026-03-17T14:24:11.171Z","avatar_url":"https://github.com/TheBoneJarmer.png","language":"C#","readme":"\u003e **Important!** It is with great sadness that I have to anounce that I no longer can find enough time to care for the project as it is. Not only do I personally no longer work with C#, there are other projects that require my attention. I recommend new projects to use [DotTiled](https://github.com/dcronqvist/DotTiled/tree/master).\n\n# TiledCS\nTiledCS is a .NET library for loading Tiled maps and tilesets. It supports only the _TMX_ and _TSX_ file formats. The library requires no 3rd-party dependencies. This way the library can be used with popular game engines like Unity3D, MonoGame and Godot.\n\n## Installation\n```\ndotnet add package tiledcs\n```\n\n## Usage\n```csharp\nusing System;\nusing System.IO;\nusing Newtonsoft.Json;\nusing TiledCS;\n\n// For loading maps in XML format\nvar map = new TiledMap(\"path-to-map.tmx\");\nvar tileset = new TiledTileset(\"path-to-tileset.tsx\");\n\n// Retrieving objects or layers can be done using Linq or a for loop\nvar myLayer = map.layers.First(l =\u003e l.name == \"monsters\");\nvar myObj = myLayer.objects.First(o =\u003e o.name == \"monster\");\n\n// Since they are classes and not structs, you can do null checks to figure out if an object exists or not\nif (myObj != null)\n{\n    var xx = myObj.x * 16;\n    var yy = myObj.y * 16;\n}\n\n// You can use the helper methods to get useful information to generate maps\nif (map.IsTileFlippedHorizontal(myLayer, 3, 5))\n{\n    // Do something\n}\n```\n\n## Examples\n### Rendering all tile layers\nWithin a layer whose `type` equals that of `tilelayer`, exists a field of type `int[]` called `data`. This array represents the gids of all tiles. A gid is a tile **index** from a tileset, _not_ the tile id as some think. In order to render a specific tile from a tileset into your spritebatch, you would need to link the gid to a tileset.\n\nIf you have multiple tilesets, you need to figure out which gid belongs to which. To help you with this process, I have added some helper methods to make this more easier for you. Let's say for example you have the following list of tilesets:\n\n```\nmain.tsx\ndungeon.tsx\noverworld.tsx\n```\n\nAnd each tileset has 10 tiles horizontal and 10 tiles vertical, then the gid's per tileset would look like this:\n\n```\nmain.tsx 1..100\ndungeon.tsx 101..200\noverworld.tsx 201..300\n```\n\nWhy? Because a tileset of 10x10 has 100 tiles in total and since 0 is used to tell that there is no tile, it starts with 1. Then the next included tileset's gid starts with the total amount of tiles from the tileset included before. Therefore you should be careful when extending an existing tileset when your map has already been drawn. The helper method `TiledMap.GetTiledMapTileset` returns a dictionary where the key represent the tileset's first gid and the value represents the tileset which is of type `TiledTileset`.\n\n\u003e **Warning!** _This works with external tilesets only for the moment. Support for embedded is on the way!_\n\nOnce you have the tileset and the gid, you can use that data to retrieve the tile's source rect. You can than use this data to render the tile. See the example below. You may need to tweak things a bit to fit for you case but below should do the trick. Be aware the `layer.width` does **not** equal the layer's total width in pixels. The `layer.width` and `layer.height` value represents the layer's horizontal tiles and vertical tiles. So you need to know your tile's size in pixels too, which can be fetched from the `TiledMap.TileWidth` and `TiledMap.TileHeight` property. \n\n```cs\nvar map = new TiledMap(\"path-to-map.tmx\");\nvar tilesets = map.GetTiledTilesets(\"path-to-map-folder/\"); // DO NOT forget the / at the end\nvar tileLayers = map.Layers.Where(x =\u003e x.type == TiledLayerType.TileLayer);\n\nforeach (var layer in tileLayers)\n{\n    for (var y = 0; y \u003c layer.height; y++)\n    {\n        for (var x = 0; x \u003c layer.width; x++)\n        {\n            var index = (y * layer.width) + x; // Assuming the default render order is used which is from right to bottom\n            var gid = layer.data[index]; // The tileset tile index\n            var tileX = (x * map.TileWidth);\n            var tileY = (y * map.TileHeight);\n\n            // Gid 0 is used to tell there is no tile set\n            if (gid == 0)\n            {\n                continue;\n            }\n\n            // Helper method to fetch the right TieldMapTileset instance. \n            // This is a connection object Tiled uses for linking the correct tileset to the gid value using the firstgid property.\n            var mapTileset = map.GetTiledMapTileset(gid);\n            \n            // Retrieve the actual tileset based on the firstgid property of the connection object we retrieved just now\n            var tileset = tilesets[mapTileset.firstgid];\n            \n            // Use the connection object as well as the tileset to figure out the source rectangle.\n            var rect = map.GetSourceRect(mapTileset, tileset, gid);\n            \n            // Render sprite at position tileX, tileY using the rect\n        }\n    }\n}\n```\n\n### MonoGame\nAs you already know, TiledCS is a generic library which does not aim at specific frameworks or libraries. That said, I have been receiving lots of requests for an example on MonoGame. However, **I do not use MonoGame**. So it is up to the community to come up with an example on how to use TiledCS within monogame. And they did:\n\n* https://github.com/Temeez/TiledCS-MonoGame-Example\n* https://github.com/ironcutter24/TiledCS-example-MonoGame\n\n\u003e **Note!** Temeez has mentioned he is no longer actively working with C# anymore. So while the example may or may not work, it is not actively maintained anymore. Be aware of that.\n\n## Building\nYou need **.NET 6** to compile TiledCS as it makes use of modern C# features that may or may not be included in earlier versions.\n\n## Version support\nIf you want to know what package supports your version of Tiled, please read the package's description.\n\n## Contribution\nFeel free to open up an issue with your question or request. If you open a pull request, please use the **develop** branch as both **source** and **target** branch. The **main** branch is supposed to be production-ready and stable. I follow the [GitFlow branching model](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) and I ask you do too.\n\n## Credits\n* A very respectful thank you to Goodlyay who introduced support for tile rotations aka flipped tiles and taught me about bitwise operators in C#.\n* A very huge thanks towards user [Temeez](https://github.com/Temeez) and [IronCutter24](https://github.com/ironcutter24) who put effort into providing a MonoGame example.\n\n## License\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthebonejarmer%2Ftiledcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthebonejarmer%2Ftiledcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthebonejarmer%2Ftiledcs/lists"}