Skip to content

Commit

Permalink
Readme update (#16)
Browse files Browse the repository at this point in the history
* Update Readme

* Update README.md

---------

Co-authored-by: Tim Schagen <schagen34@gmail.com>
  • Loading branch information
Ragath and Lightning2X authored Nov 18, 2023
1 parent 04b2dc6 commit 3af08b8
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ Cross-platform Tiled map parsing utilities.

## Nugets
[![](Docs/Images/nuget.png) TiledLib](https://www.nuget.org/packages/TiledLib/) - Core library, everything you need to read Tiled maps/tilesets.
[![](Docs/Images/nuget.png) TiledLib.Pipeline](https://www.nuget.org/packages/TiledLib.Pipeline/) - MonoGame content pipeline extension, provides a ContentImporter for Tiled maps.
[![](Docs/Images/nuget.png) TiledLib.Pipeline](https://www.nuget.org/packages/TiledLib.Pipeline/) - MonoGame content pipeline extension, provides a ContentImporter for Tiled maps.
If you add a ContentProcessor, you will be able to map the output of the supplied importer to custom classes tailored specifically for your game.

## Basic usecase
```csharp
using (var stream = File.OpenRead(filename))
{
var map = Map.FromStream(stream, ts => File.OpenRead(Path.Combine(Path.GetDirectoryName(filename), ts.source)));
var map = Map.FromStream(stream, ts => File.OpenRead(Path.Combine(Path.GetDirectoryName(filename), ts.Source)));

foreach (var layer in map.Layers.OfType<TileLayer>())
{
for (int y = 0, i = 0; y < layer.Height; y++)
for (int x = 0; x < layer.Width; x++, i++)
{
var gid = layer.data[i];
if (gid == 0)
continue;
foreach (var layer in map.Layers.OfType<TileLayer>())
{
for (int y = 0, i = 0; y < layer.Height; y++)
for (int x = 0; x < layer.Width; x++, i++)
{
var gid = layer.data[i];
if (gid == 0)
continue;

var tileset = map.Tilesets.Single(ts => gid >= ts.firstgid && ts.firstgid + ts.TileCount > gid);
var tile = tileset[gid];
var tileset = map.Tilesets.Single(ts => gid >= ts.FirstGid && ts.FirstGid + ts.TileCount > gid);
var tile = tileset[gid];

// Do stuff with the tile.
}
}
// Do stuff with the tile.
}
}
}
```

0 comments on commit 3af08b8

Please sign in to comment.