Hello Guest

Author Topic: Create tilemap layers at runtime  (Read 5504 times)

FabienC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Create tilemap layers at runtime
« on: March 11, 2015, 04:39:24 pm »
Hi Unikron,

I'm using tk2d and especially tk2dTileMap in a 2D platformer project and I really love the work you've done here !

In that project, I use multiple layers to build my level including a ground layer and several border layers.

The last are the ones I'm concerned about : In order to smooth visual aspect of ground, I generate borders around it at runtime. I need five border layers to do so. And it works really fine :)

The problem : I don't need these layers while building my level in editor mode. I want to create them at runtime but can't find out how. Is there any way to do so ?

Thanks for your answer !

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Create tilemap layers at runtime
« Reply #1 on: March 12, 2015, 11:14:19 am »
Easiest way is you create the empty layers in the editor and at runtime you can iterate through tk2dTilemap.Layers (the index corresponds to the layer index).
You can then tk2dTileMap.SetTile(x, y, layer, ...) to set tiles in there.

You can also generate the layers at runtime but its probably more trouble than its worth...

FabienC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Create tilemap layers at runtime
« Reply #2 on: March 12, 2015, 02:26:45 pm »
Thanks for your answers.

Yes, it's the way I've done things and it works just fine.

However, it really slows down my level design work. That's why I'm really interested in generating layers at runtime. You say it's possible but I can't find how to do this in docs. Can you tell me about it ?

Thanks so much !

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Create tilemap layers at runtime
« Reply #3 on: March 12, 2015, 11:34:33 pm »
Its a bit complicated, there isn't any forward facing functions that do this.
The editor function that creates a layer is tk2dTileMapUtility.FindOrCreateLayer if you're feeling adventurous...

FabienC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Create tilemap layers at runtime
« Reply #4 on: March 13, 2015, 04:09:29 pm »
Thanks for your help and your advices!

* FabienC take his hat, his wipe and march to adventure.

--------------------------------------
Btw, if you want to improve your tilemap editor, here is some user feedback :
- It could be nice to link a "custom properties" list in tile data instead of the rigid int, float, string property system (<name, value> with string name and bool, int, float, string or GameObject as value)
- It would be nice to do the same per tile on tilemap to set different parameters for each tile, or at least, make it possible to link a game object to a specific tile.
- It would be really great to make scratchpads accessible in the Inspector in the paint panel in addition to their scene box view. It would make scratchpads much more easy to use as they wouldn't hide your workspace.

I really appreciate your work here, especially for sprite and collisions optimization. I believe you've the best 2D tilemap system available on Unity. I hope you will make it even better :) Thanks a lot for bringing this to us.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Create tilemap layers at runtime
« Reply #5 on: March 13, 2015, 10:31:29 pm »
Awesome, thanks for the feedback!