How to draw an animatedtile from Tiled

Hi everyone :grinning:

Iā€™m developing a game with MonoGame and Tiled. Unfortunately i couldnā€™t grab the Animated Tile from Tiled. Is there any possibilty to get dircetly from Tiled an AnimatedTile and draw it?

This exists already:
TiledMapTilesetAnimatedTile tiledMapTilesetAnimatedTile;

Currently i have solved it by looping trough 2DSprites.

Any ideas?

Thanks!

What do you mean by ā€œget dircetly from Tiled an AnimatedTileā€?

Could you please post some code of what youā€™ve done so far?

Okay,

While iā€™m working with Tiled i need to use Monogame Extended. Monogame Extended provides us some possibilities to load the TIled map in our game.

this.map = Content.Load<TiledMap>("PATH/TO/MAP");

Thatā€™s really nice, but I have an Avatar that I want to load and animate from Tiled too.
After a long search, I have not found any documentation related to my problem.

I just found from Monogame.Extended the ā€œTiledMapTilesetAnimatedTileā€ Class but i cant really interact with it.

I realize the Tiled API is not completely intuitive. Thatā€™s something Iā€™ve been working on improving for the next version.

One thing that might help is if you have a read of the TMX Map Format page. The C# classes follow a very similar structure. In other words, if you open up your TMX file in a text editor you might be able to figure out where your animated tile is located in the code.

For example, the TiledMap class has a Tilesets property that is a collection of tilesets in the map. The tilesets are named based on the texture they use. So you might be able to do something like this (off the top of my head):

var tileset = tiledMap.Tilesets.FirstOrDefault(t => t.Name == "mytileset");
var myTile = tileset.Tiles.FirstOrDefault(t => t.LocalTileIdentifier == 9);
var animatedTile = (TiledMapTilesetAnimatedTile) myTile;

and once youā€™ve got the animated tile you can get access to the animation frames and so onā€¦

All of the data you need is in there and you can get to it but of course it hasnā€™t been designed for this use case yet so itā€™s a bit fiddly.

Thank for your quick response.

I have already managed to get the animatedTile. At this point i was able to get the TiledMapTilesetTileAnimationFrame.
Is there any possibility to cast/convert it to a Texture2D object or to draw it directly.

(Because the spritebatch.Draw method just accepts a Texture2D object)

Thank you very much for your Help.

-Karim