This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
forked from TheBoneJarmer/TiledCS
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
corrected layering, added embedded tileset support, and added a example
- Loading branch information
nolemretaW
committed
Sep 12, 2023
1 parent
b7b9ead
commit ea19cff
Showing
12 changed files
with
179 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using TiledCSPlus; | ||
|
||
class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
//load a tilemap | ||
TiledMap TiledMap = new TiledMap("assets/tilemap.tmx"); | ||
|
||
//load a tileset by loading all used tilesets from a directory | ||
Dictionary<int, TiledTileset> Tilesets = TiledMap.GetTiledTilesets("assets/"); | ||
//you can load them manually of course, like this | ||
/* foreach (TiledMapTileset tiledMapTileset in TiledMap.Tilesets) | ||
{ | ||
if tileset is not embedded into tilemap | ||
if (!tiledMapTileset.IsTilesetEmbedded) | ||
{ | ||
load a tileset file using tiledMapTileset.Source as a filename... | ||
...using new TiledTileset() | ||
TiledTileset tiledTileset = new TiledTileset(tiledMapTileset.Source); | ||
..or other method that works for you, into a MemoryStream | ||
MemoryStream ms = new MemoryStream(<loaded tileset file>); //file has to be loaded into a byte array | ||
TiledTileset tiledTileset = new TiledTileset(ms); | ||
//then, add into loaded tilesets as usual | ||
Tilesets.Add(tiledMapTileset.FirstGid, tiledTileset); | ||
} | ||
} */ | ||
|
||
//get map tileset which some tile belongs to | ||
TiledMapTileset tileMapTileset = TiledMap.GetTiledMapTileset(TiledMap.Layers[0].Data[0]); | ||
//now that you have tileset laded into Tilesets dictionary, you can get the tileset by | ||
TiledTileset tileTileset = Tilesets[tileMapTileset.FirstGid]; | ||
//and now, get the rect for tile's position in the tileset image | ||
TiledSourceRect rect = TiledMap.GetSourceRect(tileMapTileset, tileTileset, TiledMap.Layers[0].Data[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TiledCSPlus\TiledCSPlus.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="assets\tilemap.tmx"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="assets\tileset.png"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="assets\tileset.tsx"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<map version="1.8" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="1"> | ||
<tileset firstgid="1" source="tileset.tsx"/> | ||
<layer id="1" name="Tile Layer 1" width="10" height="10"> | ||
<data encoding="base64"> | ||
AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAA== | ||
</data> | ||
</layer> | ||
</map> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<tileset version="1.8" tiledversion="1.10.2" name="tileset" tilewidth="16" tileheight="16" tilecount="1" columns="1"> | ||
<image source="tileset.png" width="16" height="16"/> | ||
</tileset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<map version="1.8" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" backgroundcolor="#04010203" nextlayerid="2" nextobjectid="1"> | ||
<map version="1.8" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" backgroundcolor="#04010203" nextlayerid="5" nextobjectid="1"> | ||
<tileset firstgid="1" source="tileset.tsx"/> | ||
<tileset firstgid="2" name="tileset-embedded" tilewidth="16" tileheight="16" tilecount="1" columns="1"> | ||
<image source="tileset.png" width="16" height="16"/> | ||
</tileset> | ||
<layer id="1" name="Tile Layer 1" width="10" height="10" tintcolor="#fcfffefd"> | ||
<data encoding="base64"> | ||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== | ||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAAAAAQAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAQAAAAEAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== | ||
</data> | ||
</layer> | ||
<objectgroup id="2" name="Object Layer 1"/> | ||
<imagelayer id="3" name="Image Layer 1"/> | ||
<group id="4" name="Group Layer 1"/> | ||
</map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.