TiledSharp

repository·master·Indexed 43 days ago

https://github.com/marshallward/tiledsharp

A .NET C# library for importing and parsing TMX tile maps and TSX tilesets generated by the Tiled map editor. It provides a data interface via the TmxMap object for game engines like Unity, MonoGame, or XNA, without providing rendering logic. Note: This project is no longer maintained; TiledCS is recommended as an alternative.

Tokens
1.1K
Snippets
4
Records
6
Agent score
6%

What's inside TiledSharp

  1. Import TMX tilemaps with TiledSharp

    master

    TiledSharp is a .NET C# library designed to import TMX tilemaps and TSX tilesets generated by the Tiled map editor. It parses these files into a TmxMap object that mirrors the original TMX file structure.

    Note that TiledSharp is a generic parser; it does not handle rendering. It is intended to serve as the data interface between TMX files and your game engine (such as Unity, MonoGame, or XNA).

  2. Set up and use TiledSharp in a C# project

    master

    To use TiledSharp in your application, follow these steps:

    1. Include the library: Add a reference to TiledSharp by either incorporating the source code directly into your project or including the pre-compiled DLL.
    2. Import the namespace: Add using TiledSharp; to your C# file.
    3. Initialize the map: Use the TmxMap constructor, passing either a file path or a resource name.
    4. Access data: Use the properties and indexers on the TmxMap instance to retrieve map data.
    using TiledSharp;
    
    // Load the map using a file path or resource name
    var map = new TmxMap("someMap.tmx");
    
    // Accessing data
    var version = map.Version;
    var myTileset = map.Tilesets["myTileset"];
    var myLayer = map.Layers[2];
    var hiddenChest = map.ObjectGroups["Chests"].Objects["hiddenChest"];
  3. Import TMX tile maps into C#

    master

    To use TiledSharp in your application, include a reference to the TiledSharp DLL or incorporate the source directly into your project. You can then instantiate a TmxMap object by passing either a file path or a resource name to its constructor. This object serves as the primary entry point for accessing parsed TMX and TSX data.

    using TiledSharp;
    
    // Load a map using a file path or resource name
    var map = new TmxMap("someMap.tmx");
  4. Important notice: TiledSharp is no longer maintained

    master

    Maintenance Status

    TiledSharp is no longer being maintained.

    For projects requiring active support or a greater number of features, it is recommended to use the TiledCS project instead, which offers a similar API.

  5. Access TMX data via TmxMap

    master

    Once a TmxMap is instantiated, you can navigate the map hierarchy using names (strings) or indices. The structure closely follows the TMX specification.

    Common access patterns include:

    • Properties: Direct access to metadata like Version.
    • Tilesets: Access via name indexer: map.Tilesets["name"].
    • Layers: Access via index: map.Layers[index].
    • ObjectGroups: Access groups by name and objects within them by name: map.ObjectGroups["GroupName"].Objects["ObjectName"].

    Note: While TiledSharp can manage multiple elements with the same name, it is not recommended to rely on this behavior.

    var map = new TmxMap("someMap.tmx");
    var version = map.Version;
    var myTileset = map.Tilesets["myTileset"];
    var myLayer = map.Layers[2];
    var hiddenChest = map.ObjectGroups["Chests"].Objects["hiddenChest"];
  6. Access TMX data from a TmxMap object

    master

    Once a TmxMap is instantiated, you can access its data fields, which closely mirror the structure of the original TMX file. Principal collections and elements can be accessed using either their name (string indexer) or their numerical index.

    Common access patterns include:

    • Accessing properties like Version.
    • Accessing Tilesets by name or index.
    • Accessing Layers by index.
    • Accessing ObjectGroups by name, and then accessing specific Objects within that group by name.
    var map = new TmxMap("someMap.tmx");
    
    // Accessing properties and collections
    var version = map.Version;
    var myTileset = map.Tilesets["myTileset"];
    var myLayer = map.Layers[2];
    var hiddenChest = map.ObjectGroups["Chests"].Objects["hiddenChest"];