Hello Guest

Author Topic: Problems importing TMX properties, animations and loading it in running time  (Read 4574 times)

danpelgar

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Hello!

We are currently converting a game from another engine, and we’re having problems importing the tmx of tiled in the way we would like to do, so I’d like to ask you a few questions:

1.- We would like to import the tilemap directly through code. Is it possible to do that? (I’ve looked for it in the forum but I couldn’t find a lot about it. A little bit of help here would be appreciated :))

2.- We need to be able to access to the properties of the tiles that were written in the tmx. We use that to differentiate the kind of interactions that will happen with the character and also to set the spawn points of enemies and items. It would be too much to do that with the ids of the tiles. Is there a possibility to do this myself?

3.- We also would like to use animated tiles. In tiled the animations are done practically automatically and we only have to load the map. Is there a way to do this automatically or do I have to replace each animated tile with a animated sprite? This would be also a lot of effort…

Thank you very much for your help!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
1. Not out of the box but you have full source code so you could do anything you like. The part of code that imports the tmx is in tk2dTileMapImporter.cs, its editor only as it has a dependency to Zlib.net. You could get it to work at runtime with a bit of effort.
2. Yes I don't see why not.
3. You would have to replace with animated sprites, or do something else using materials / shaders. Once again, you don't have to do this by hand, you can write an editor script to do it for you.

LaserDinosaur

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
For #3, you can use prefabs with tk2d animators attached to them and then add them as a data tile. At the end of this tutorial, part 5 talks about data tiles. Just replace the steps adding a rigidbody with adding a tk2dAnimator script.

The drawback is you can't flip or rotate data tiles without adding some extra custom code, even though when you paint them into the scene with the tile editor they will appear flipped/rotated (they reset when you run the scene). Just be aware if you do modify the code to allow rotation, it will break batching which can affect performance (or at least it used too).