2D Toolkit Forum
2D Toolkit => Support => Topic started by: stuntboots on March 07, 2014, 04:55:07 am
-
Hi there,
I'm wondering if it's possible to set up objects that all use the same tiling coordinates? So basically I move an object, and the tile stays in position while the object moves around? Basically so that wherever I move an object, when it touches another object with the same tile, the tiles will match perfectly?
Any and all help appreciated!
-
The easiest (and most efficient) way to do this is to modify the shader so instead of using internal texture co-ordinates it uses world coordinates. You also probably don't want this texture to be atlased as it won't be trivial to tile it then.
-
Thanks for the reply! I don't suppose you have any direction on the modified shader? Also what does it not being trivial mean?
-
It should be straightforward with the shader - just take one of the tk2d shaders, and do replace it like this maybe -
o.texcoord = mul(_Object2World, v.vertex).xy * 0.1;
You'll have to tweak the multiplier in the end to get it to tile the way you want.
If you want to do this from an atlased texture, then you'll have to manually tile which is considerably more complicated.
-
It's definitely creating the effect I'm after, in that when I move the game object around it just scrolls through the tile, but the tiling is behaving very strangely no matter what I change the multiplier to.
(http://woheva.com/globaltiling.jpg)
That's the tile in the top right corner, and the result below (One to illustrate the actual tiles.) I copied the BlendVertexColor shader because that's what I was using for the initial tiling result.
Thanks again for the help!
-
Additionally when I press 'Play', the material switches back out to BlendVertexColor for some reason. Obviously user error, but I'm not sure what my error is, hehe.
-
Hi again, sorry for the little bump. I tried our old friend Google for some global position shader help to no avail, was just hoping you could help me out? Also let me know whether I need to edit the 2dTK shaders directly, as it seems to change the shader at run time.
-
You need to create a new shader. You also need to assign the shader to the atlas material, not just the sprite.
About the position thing - you'll probably have to change the scales for it to work better. Try 0.01, then 10, and keep decreasing and increasing to work out whats best.
-
Excellent, got it! Thanks for your help. I'm also having an issue where if I have a 128x128 sprite, and try to put it into a 128x128 atlas, it tells me it can't fit. I had a look at the tutorial and it told me to either increase the atlas or dice the sprite, but it's just the one sprite (for the aforementioned tiling), and it should technically fit perfectly, what am I missing?
-
Its adding padding. If you only have one sprite, you don't need an atlas. You can simply use sprite from texture - http://2dtoolkit.com/docs/latest/reference/sprite_from_selected_texture.html
-
Ah great. I'd noticed the error when trying to get four sprites on a large atlas as well. Can I ask what the reasoning is for padding when you're dealing with absolute pixel values?
-
You need padding for filtering. You get weird edge bleeding artefacts, shimmering edge lines, otherwise.
-
Ah, excellent! Thanks for all your help!
-
Hi again!
So I'm trying to use the iTween FadeTo tween, and with my version of the BlendVertexColor shader it's telling me there's no color property '_Color'. Obviously this is because it doesn't exist, but I'm wondering if there's a way to add alpha/the _Color property to the shader?
-
You will have to add that in manually to the shader. Refer to the unity shader source (https://unity3d.com/unity/download/archive) for examples on how to do it.
In most cases you don't really want to do that that - I'm guessing you want to change the colour of one sprite, and not all sprites using that atlas? If so, have a look at this thread (http://2dtoolkit.com/forum/index.php/topic,1164.msg5545.html#msg5545) - it uses hotween to do that. I don't use iTween so I can't give you any advice on how you'd achieve the same with that.
-
Ah yeah, I used the Unity shader guide to add a colour channel, seems to work fine! Thanks for your help.