Hello Guest

Author Topic: Tilemap Tile Changing  (Read 5212 times)

nicktp491

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Tilemap Tile Changing
« on: September 05, 2013, 12:11:58 am »
I wanted to be able to change a tile in the tile map during run time and it seems to be working but the visual representation is not changing.  Here's the code I am using.

tk2dTileMap temp;
temp = gameObject.GetComponent<tk2dTileMap>();
temp.SetTile(1,1,0,16);

It's changing the tile because I have this line of code:
GUI.Label(new Rect(10, 90, 200, 20), "tile id = " + tileMapFinder.GetTileIdAtPosition(v3Position,0));
And it tells me that the value of the tile id did change, but the sprite didn't.

Do I need to somehow update the TileMap's render data or am I trying to change the Tilemap's sprite incorrectly?

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: Tilemap Tile Changing
« Reply #1 on: September 05, 2013, 08:43:09 am »
Yes, you need to update by calling Build() after changing the tile. It's done this way so you can change lots of them if needed and then update the mesh at the end.

nicktp491

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Tilemap Tile Changing
« Reply #2 on: September 06, 2013, 03:11:40 am »
Yes, you need to update by calling Build() after changing the tile. It's done this way so you can change lots of them if needed and then update the mesh at the end.

Calling Build(); doesn't seem to do anything.  I did find a thread that said the the tile map feature wasn't completed and wasn't supported so it may be one of those things that haven't been tested yet.  But I did create an alternative for what I needed accomplished.  Thanks for your suggestion though.

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: Tilemap Tile Changing
« Reply #3 on: September 06, 2013, 03:25:33 am »
Most likely that is from an old thread - I think Tilemap was officially 'released' in version 2.1, and it certainly is now supported. I've personally used SetTile and Build at runtime so it does work.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap Tile Changing
« Reply #4 on: September 06, 2013, 01:45:04 pm »
SetTile and Build definitely works - the entire editor is built upon those functions. Build triggers the geometry rebuild - you'll not see a visible change otherwise.
The Build function wasn't documented correctly in 2.1 in the script reference, but it will be in 2.2.