Cammin / LDtkToUnity

Unity importer for the LDtk level editor
https://cammin.github.io/LDtkToUnity
MIT License
388 stars 39 forks source link

Possible to get animated tiles? #41

Closed yiliansource closed 6 months ago

yiliansource commented 1 year ago

Since LDtk has yet to implement animated tiles, I was wondering whether there was a possibility to inject an animated tile during the import process. The usecase is an animated water tile. I'd appreciate any ideas!

Cammin commented 1 year ago

It's something I plan to allow easy support for, but you may be able to do some coding on your end to replace certain tiles with a custom animated tile of your own from 2d extras. Another option is to make your animated tiles as entities. It's something I eventually want to get to.

yiliansource commented 1 year ago

Do you have an idea on how to do such a replacement? Any pointers would be really helpful.

pinwizkid commented 1 year ago

One way is to make a prefab with the animation as part of the prefab. Then you can either make entities for each animated tile, or create a dedicated intgrid layer for the animated tile. You can only assign one prefab per entity or intgrid, so it's a bit of a manual process. Using the entity method will allow you to make animated tiles of different sizes since you can control entity size and aren't limited to the size of a grid cell (this isn't the case if going the intgrid route since those are tile based).

yiliansource commented 1 year ago

That makes sense.

Do you think it's possible to access the actual tilemap during the import step, so you can replace dedicated auto/rule-tiles with their animated counterparts? Are the tiles exposed during the import process?

Cammin commented 1 year ago

It would be possible to access the tilemap in the import process via the LdtkPostprocessor class, but since the tiles are generated every reimport, it would naturally be difficult to have an exposed reference to the tiles.

You may be able to define a string of the tiles you want to replace. Each tile is named according to a specific convention: "TilesetName_x_y_w_h" You should be able to iterate though the tilemap and check the names of particular tiles to figure out which ones you want to replace. It's not the easiest process, but it's something doable right now. I have plans to make this easier, but it shall come in due time when it does 🙂

devingDev commented 1 year ago

I thought it supported this but sadly it doesn't. Would be a great addition although I'm sure it'll be lots of work. Hope to see it sometime 😄 Keep up the great work and thanks for this tool!

Cammin commented 1 year ago

Yeah, since LDtk doesn't have a concept of animated tiles, I'd invent a custom solution. This is a feature that will need to come after I get the tileset def update working perfect. I have subtle plans for animated tiles and stubbed some initial code, but it needs to wait for some other stuff that I'm cooking 🙂

Cammin commented 6 months ago

I got animated tiles implemented in the new update! (5.0.0) Give them a try and let me know if there are any problems. Here's the guide: https://cammin.github.io/LDtkToUnity/documentation/Topics/topic_AnimatedTiles.html