2D Toolkit Forum
2D Toolkit => Support => Topic started by: roaet on August 31, 2013, 07:01:05 am
-
I really like tilemaps but I have level data stored externally and would like to generate them runtime. Is that possible? Thanks for the support. Love your product!
-
Hi,
There isn't an "official" way to create tilemaps at runtime, as a lot of the code is simply stored in editor code to reduce runtime bloat. Easy option - create a HUGE tilemap (max size is fine), but keep it empty. Then you can tweak as necessary at runtime - empty tilemaps don't really take up that much memory (close to negligible).
Or do the above, create a prefab and instantiate at runtime. The tilemap requires the data / editor data objects, which are a pain to generate at runtime.
-
You could use
tileMap.Layers[i].SetTile(x, y, id)
to set the tiles at runtime. You can get the id via
tileMap.SpriteCollectionInst.GetSpriteIdByName("YOURSPRITENAME")
At the end, use
tileMap.Build()
to build the actual tilemap.
-
For anyone who is interested, I posted a comprehensive guide to dynamically creating a TileMap here: http://praveenangyan.com/2014/03/02/dynamically-displaying-a-level-with-tk2dtilemap-in-2d-toolkit-for-unity/ (http://praveenangyan.com/2014/03/02/dynamically-displaying-a-level-with-tk2dtilemap-in-2d-toolkit-for-unity/)