Hello Guest

Author Topic: Is there a way to interact with a tilemap from scripting?  (Read 4400 times)

brianjenkins94

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Is there a way to interact with a tilemap from scripting?
« on: June 19, 2013, 06:15:11 am »
Perhaps I missed something in the documentation, I was wondering if there was a way to perhaps, draw a tilemap from C#, or change specific tiles, etc.

On a slightly less related note, I love 2D toolkit. You guys should feel great about the work you do. Thank you. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is there a way to interact with a tilemap from scripting?
« Reply #1 on: June 19, 2013, 12:12:14 pm »
The tilemap docs are indeed a bit lacking due to it being in beta. It will improve massively in the next version (2.1).

1. You can't resize tilemaps from code, this is intentional, but you can safely create a HUGE one to start with, the overhead for an empty tilemap is very very low.
2. You can change tiles on a tilemap after you get a reference to it. eg. tilemap.Layers[0].SetTile( x, y, 1 ); tilemap.Layers[0].GetTile(x, y ); returns a tileId. These functions are likely to change in 2.1, though, which is why they aren't documented! Call tilemap.Build(); after you change what you need to.
3. There are also some documented functions in tk2dTileMap.cs which you can find by browsing the file (look for <summary>) - as the APIs aren't final, hence the reason it not being in the docs.

Hope that helps, and glad you're loving 2D Toolkit :)

M.O.

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Is there a way to interact with a tilemap from scripting?
« Reply #2 on: August 02, 2013, 03:32:57 pm »
 Is there a way to attach a script to a tile?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is there a way to interact with a tilemap from scripting?
« Reply #3 on: August 02, 2013, 03:37:54 pm »
Use the data tab to create a sprite prefab. The tutorial shows you how you do that:
http://unikronsoftware.com/2dtoolkit/doc/2.10/tilemap/tutorial.html