Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TiledMapTileReader does not resolve object type TiledMapObjectType.Tile #934

Open
Mephisztoe opened this issue Aug 26, 2024 · 2 comments
Open
Milestone

Comments

@Mephisztoe
Copy link

I used Tiled to create a tiled map.

So that I can add static visual assets offgrid, I added an Object Layer and used the "T"-shortcut with on selected tiles.

You can see the result here:
image

For now, it is not possible to make MonoGame.Extended just render an object layer the same way a tile layer is rendered, although loading and manually accessing its content is pretty much identical.

So I wanted to manually spritebatch the objects.
When trying to identify the objects' source rectangles within their respective tilesheet, I noticed, that I am not able to access their global identifiers. Also, I noticed that the TilesMapTileReader does not populate the Tile property on the TiledMapTileObject which kind of seems like an issue to me.

Here is a little repro-solution (the assets being used are taken from one of the Kenney Game Asset Packs):
ObjectLayerIssueRepro.zip

@Mephisztoe
Copy link
Author

So apparently this one is sort of a duplicate of this one.

Here is how I fixed it for the moment:

  1. In Tiled, I edited the TileSheet and added a Class description.
    image

  2. By doing so, the tiles get added to the TileSheets' .tsx file.

<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.9" tiledversion="1.10.2" name="Roguelike_RPG" tilewidth="16" tileheight="16" spacing="1" tilecount="1767" columns="57">
 <image source="roguelikeSheet_transparent.png" width="968" height="526"/>
 <tile id="420" class="Decoration"/>
 <tile id="478" class="Decoration"/>
 <tile id="482" class="Decoration"/>
</tileset>
  1. Because the TiledMapTileReader can now populate the Tiled property of the TileMapTileObject objects, I can now retrieve their source rectangles and draw them properly
private void DrawObjectLayer(SpriteBatch spriteBatch, TiledMap tiledMap)
{
    foreach (var obj in decorationLayer.Objects)
    {
        if (obj is TiledMapTileObject tileObject)
        {
            var tileset = tileObject.Tileset;
            var localIdentifier = tileObject.Tile.LocalTileIdentifier;
            var tileHeight = tileset.TileHeight;             

            var sourceRectangle = tileset.GetTileRegion(localIdentifier);

            var position = new Vector2(tileObject.Position.X, tileObject.Position.Y - tileHeight);

            spriteBatch.Draw(tileset.Texture, position, sourceRectangle, Color.White);
        }
    }
}

Result:
image

However, I'd vote for ninjeffs suggestion here.

@AristurtleDev AristurtleDev added this to the v4.1.0 milestone Nov 7, 2024
@AristurtleDev
Copy link
Collaborator

Tiled implementation is going to be overhauled, currently looking into existing solutions such as DotTiled to see what can be used for improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@Mephisztoe @AristurtleDev and others