2D Toolkit Forum

2D Toolkit => Support => Topic started by: brianjenkins94 on June 19, 2013, 06:15:11 am

Title: Is there a way to interact with a tilemap from scripting?
Post by: brianjenkins94 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. :)
Title: Re: Is there a way to interact with a tilemap from scripting?
Post by: unikronsoftware 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 :)
Title: Re: Is there a way to interact with a tilemap from scripting?
Post by: M.O. on August 02, 2013, 03:32:57 pm
 Is there a way to attach a script to a tile?
Title: Re: Is there a way to interact with a tilemap from scripting?
Post by: unikronsoftware 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