2D Toolkit Forum
2D Toolkit => Support => Topic started 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?
-
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.
-
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?
-
No there isn't, it really doesn't use 2D Toolkit - you'll have to roll your own framelist code there.
-
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?
-
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.
-
But how I change it runtime so I get animated tiles?
-
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.
-
One more thing. How I should count right amount for offset from texture size / tilesize?
-
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.