Hello Guest

Author Topic: Tilemap - How to acquire the string info from a tile?  (Read 5844 times)

regnared

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Mah website
Tilemap - How to acquire the string info from a tile?
« on: November 08, 2012, 08:16:10 pm »
How would you code-wise get the information of particular tiles? Say I want to use that string field to add different information to the tile.
When there is a collision with a tile I want to check its property.

Solid, non-solid, ice, breakeable, slow, hurtful , poison, etc. (Things that would not make sense to prefab, etc.)




Or maybe it could be cool to have the possibility to add properties fields to tiles. A bit like Unity does with tags.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap - How to acquire the string info from a tile?
« Reply #1 on: November 09, 2012, 06:29:00 pm »
Code: [Select]
int tileId = tileMap.GetTileIdAtPosition(pos, layer);
if (tileId >= 0)
{
      tk2dRuntime.TileMap.TileInfo tileInfo = tileMap.GetTileInfoForTileId(tileId)
      string str = tileInfo.stringVal;
}

That should do it

regnared

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Mah website
Re: Tilemap - How to acquire the string info from a tile?
« Reply #2 on: November 11, 2012, 09:55:43 pm »
I've searched in the documentation but didn't find a solution. How do you go about acquiring the tileMap information to work in your code?

Something like : tileMap = GameObject.Find("Map Render Data"); ??

Or do you use prefabs?

I know how to move tk2dsprites around the scene, find gameobjects and play with their basic unity information, but actually acquiring the object and its tk2d information I'm not sure how.

Thanks for the help so far. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap - How to acquire the string info from a tile?
« Reply #3 on: November 11, 2012, 11:00:52 pm »
You should do it as you would referencing any other object in Unity.
In your script, add a variable

public tk2dTileMap tileMap;
and from the inspector, drag the tilemap object onto it to link it to the reference.

regnared

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Mah website
Re: Tilemap - How to acquire the string info from a tile?
« Reply #4 on: November 11, 2012, 11:40:55 pm »
Sorry about my noobies questions, I didn't know you could use tk2d variables directly with the unity inspector. (Used to only use Unity variables for that).

Everything is working really nicely now! A big thank you for helping me out. This knowledge helped me out way more then you can imagine. :) Rarely have I experienced awesome support by passionate people. :)

Thanks for making a really sweet tool.  ;D

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap - How to acquire the string info from a tile?
« Reply #5 on: November 12, 2012, 12:55:01 am »
Glad its sorted, and really glad you like 2D Toolkit :)