2D Toolkit Forum

2D Toolkit => Support => Topic started by: DJVDJV on May 14, 2015, 09:33:39 pm

Title: Confusuon about animated tiles on tilemap
Post by: DJVDJV 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?

Title: Re: Confusuon about animated tiles on tilemap
Post by: unikronsoftware 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.
Title: Re: Confusuon about animated tiles on tilemap
Post by: DJVDJV 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?
Title: Re: Confusuon about animated tiles on tilemap
Post by: unikronsoftware 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.
Title: Re: Confusuon about animated tiles on tilemap
Post by: DJVDJV 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?
Title: Re: Confusuon about animated tiles on tilemap
Post by: unikronsoftware 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.
Title: Re: Confusuon about animated tiles on tilemap
Post by: DJVDJV on May 18, 2015, 07:11:45 am
But how I change it runtime so I get animated tiles?
Title: Re: Confusuon about animated tiles on tilemap
Post by: unikronsoftware 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.

Title: Re: Confusuon about animated tiles on tilemap
Post by: DJVDJV on May 18, 2015, 02:01:43 pm
One more thing. How I should count right amount for offset from texture size / tilesize?
Title: Re: Confusuon about animated tiles on tilemap
Post by: unikronsoftware 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.