Hello Guest

Author Topic: Confusuon about animated tiles on tilemap  (Read 6240 times)

DJVDJV

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Confusuon about animated tiles on tilemap
« on: May 14, 2015, 09:33:39 pm »
Hello,

Wondering about animated tiles on map (Like lava or water)

How I should implement this (For get still good performance on mobile)

Maps can have even 10000 tiles.

1) Make every lava / water prefab and animate it (I strongly think I should avoid this)
2) Make own atlas for every frame of tiles and change atlas on code
3) Something like this: https://gist.github.com/treefortress/2c9b034e696953bd83fc
4) Something that I have not mentioned?


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #1 on: May 14, 2015, 11:16:16 pm »
1. Avoid at all costs, unless you only have very few animated tiles.
2. This will be very efficient. Consider this as an option.
3. This is ok but 2 will be way more efficient.

DJVDJV

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #2 on: May 15, 2015, 11:56:03 am »
2) Make own atlas for every frame of tiles and change atlas on code

Is there any example how I should do this right way?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #3 on: May 15, 2015, 10:49:19 pm »
No there isn't, it really doesn't use 2D Toolkit - you'll have to roll your own framelist code there.

DJVDJV

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #4 on: May 16, 2015, 01:43:45 pm »
I tried like this:

terrainTileMap.SpriteCollectionInst.material = terrainTileMap.SpriteCollectionInst.materials[1];
terrainTileMap.Build();

(I added additional material with other sprite to 2DTileCollectiosData materials)

But it does not work. What I do wrong or it this even right way to do it?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #5 on: May 17, 2015, 05:45:36 pm »
You will need to set up multiple materials in the sprite collection editor -
http://2dtoolkit.com/docs/latest/tutorial/multiple_materials_in_a_sprite_collection.html

You shouldn't need to mess with materials directly otherwise apart from changing shaders, etc.

DJVDJV

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #6 on: May 18, 2015, 07:11:45 am »
But how I change it runtime so I get animated tiles?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #7 on: May 18, 2015, 09:55:49 am »
You can animate in the shader, or grab the material and modify UV scale and offset using a script - it will change all instances of that material, i.e. all your animated tiles of that type. You'll need to do a bit of work for UVs but get the basic stuff working first and I can advise on that.


DJVDJV

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #8 on: May 18, 2015, 02:01:43 pm »
One more thing. How I should count right amount for offset from texture size / tilesize?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Confusuon about animated tiles on tilemap
« Reply #9 on: May 19, 2015, 11:37:19 pm »
Quote
How I should count right amount for offset from texture size / tilesize?
This should only depend on your texture - remember you want to store all the frames for your animated sprite in a different texture, ideally the frames stored in a grid. Ie. if you drop the material / shader on a normal unity plane it should animate correctly.