Unity 2d sprite details looking different at small size and in big numbers - unity3d

I am trying to create grid with small squares, my square sprite has a black outline but the outline looks thicker at some areas and thinner in some other areas. How can i fix it?
Here is the look i got by snapping them without leaving any place inbetween.
https://imgur.com/a/J5U2nVk

I have done some testing to reproduce your screenshot, and at the end I think this is a very simple problem: Unity does that when it tries to render high definition sprites with a low scale ( think of it as multiple pixels of a sprite fighting each other for one pixel of your screen ), so for you I think the solution would be to use less detailled sprites.

Related

2D sprite problem when setting up an instant messaging UI

I'm new to Unity and to game development in general.
I would like to make a text-based game.
I'm looking to reproduce the behavior of an instant messenger like messenger or whatapp.
I made the choice to use the Unity UI system for the pre-made components like the rect scroll.
But this choice led me to the following problem:
I have "bubbles" of dialogs, which must be able to grow in width as well as in height with the size of the text. Fig.1
I immediately tried to use VectorGraphics to import .svg with the idea to move runtime the points of my curves of Beziers.
But I did not find how to access these points and edit them runtime.
I then found the "Sprite shapes" but they are not part of the "UI",
so if I went with such a solution, I would have to reimplement
scroll, buttons etc...
I thought of cutting my speech bubble in 7 parts Fig.2 and scaling it according to the text size. But I have the feeling that this is very heavy for not much.
Finally I wonder if a hybrid solution would not be the best, use the
UI for scrolling, get transforms and inject them into Shape sprites
(outside the Canvas).
If it is possible to do 1. and then I would be very grateful for an example.
If not 2. 3. 4. seem feasible, I would like to have your opinion on the most relevant of the 3.
Thanks in advance.
There is a simpler and quite elegant solution to your problem that uses nothing but the sprite itself (or rather the design of the sprite).
Take a look at 9-slicing Sprites from the official unity documentation.
With the Sprite Editor you can create borders around the "core" of your speech bubble. Since these speech bubbles are usually colored in a single color and contain nothing else, the ImageType: Sliced would be the perfect solution for what you have in mind. I've created a small Example Sprite to explain in more detail how to approach this:
The sprite itself is 512 pixels wide and 512 pixels high. Each of the cubes missing from the edges is 8x8 pixels, so the top, bottom, and left borders are 3x8=24 pixels deep. The right side has an extra 16 pixels of space to represent a small "tail" on the bubble (bottom right corner). So, we have 4 borders: top=24, bottom=24, left=24 and right=40 pixels. After importing such a sprite, we just have to set its MeshType to FullRect, click Apply and set the 4 borders using the Sprite Editor (don't forget to Apply them too). The last thing to do is to use the sprite in an Image Component on the Canvas and set the ImageType of this Component to Sliced. Now you can scale/warp the Image as much as you like - the border will always keep its original size without deforming. And since your bubble has a solid "core", the Sliced option will stretch this core unnoticed.
Edit: When scaling the Image you must use its Width and Height instead of the (1,1,1)-based Scale, because the Scale might still distort your Image. Also, here is another screenshot showing the results in different sizes.

Using shader graphs to add an outline to a sprite of a tank. Despite following tutorials, the outline distorts the sprite

I'm trying to add a black outline surrounding a sprite I have for a tank.
I've tried following every tutorial I could find on 2d outlines for sprites, however almost all of them were done using a previous unity version (I'm using 2021.1.3f1) and don't seem to have any of the problems I've been having.
After using Alpha subtraction on an offset copy of the sample texture (and multiplying by a color) I then try to add it back to the original sample texture. That's when things go wrong, no matter what I've tried it keeps either chopping off the right side of the sprite (I was trying to add the left outline first), or making the right side of the sprite the opposite color of what I'm putting on the left.
What I mean by "cutting off the right", those treads should be the same thickness on the right as on the left, it's like adding the outline to one side trimmed the other.
If it matters, the sprite is a PNG I got from Kenney and then modified in Krita.
For whatever reason, changing the color of the outline seems to also change how much is getting trimmed.
I've been banging my head against this for four hours now, any ideas or suggestions are greatly appreciated.
Update: After following One Full Time Equivalent's suggestion below I do get an outline surrounding the entire sprite, but now it's distorting the colors at the edges of the sprite as seen here:
After replacing Add with Blend
After your subtraction node, put in an Absolute node, otherwise you will subtract the right edge in the alpha channel (this is exactly what you observe right now). Always be aware that you can only see half the color space and negative channels can be tricky to deal with.

Annoying lines between cubes while the Camera is moving in Unity3D

I made lot of cubes in a mesh with vertices. When I tested with color textures I could clearly see the lot of annoying gaps and lines popping up while the Camera is moving.
The mesh looks like this:
This is what it looks like when the camera is moving:
As the gif shows, there are lines popping up, how can I fix this?
Looks like "z-fighting". When two or more meshes overlap, placed very close together, rounding errors will cause them to fight when rendered. Possible solutions:
Create one cube and give it a material/texture with the desired colors.
Create three cubes on top of each other (do not let one, like the black one in your example, be bigger so it is overlapped by the red one).
If you really want to overlap the cubes, make them slightly different in size so the rounding errors will not show up.

Unity3D - Make texture edges not stretch

I've been searching around for this one for a bit, and unfortunately I can't seem to find any good, consistent results. So, in the Unity UI system, buttons can stretch without becoming pixelated or distorted. This is because the texture is split up into 9 parts - the corners, middle, and sides.
This works because the button's middle and sides are stretched, but not the corners. Then, the button appears not pixelated, at any dimension.
So, the question is as follows: How can I do the same thing for a transparent, unlit texture in 3D space? I have a speech bubble texture on a flat plane that I know how to re-scale to fit the text in the speech bubble.
I've set the texture type to Multiple Sprite, and divided it up into 9 parts. However, I cannot seem to find where I can set the texture to act like the UI button does, and I'm not sure that this is even possible in this way in 3D space.
Is there a way, or should I just make the different parts of the texture different objects, and move them together? That would seem very inefficient and ugly compared to this.
To accomplish what you are asking, you would need to create tiles for this speech bubble and then write a script that procedurally builds a speech bubble based on the plane's scale value. You could also try just changing the texture's Filter Mode to Point.
However I really don't think you should be using textures for this anyway. Why not just use a Unity Canvas and set the Render Mode to World Space? Then you can just set your text box to be a sprite, not a texture, and set its filter mode to Point (See below). This would also make it a lot easier for when you want there to be text in the speech bubble later on.

Cocos2D changes the colours in the last row of pixles in a sprite?

I have never seen this issue before, its very strange. Just wondering if anyone else has come across this too.
I have added a sprite to my game, its supposed to be the top left corner of a box to put text on to. I want to make it scalable without loosing anything so i have it broken up into sections. In the image above the one on top is the image itself, and then the one on the bottom is the image when its being drawn in the iPhone simulator.
Any idea why the last column of pixels on the right are altered? I have not scaled the image at all.
I don't know about Cocos2D, but in general terms what you've done here is to draw the image at a position that isn't an exact multiple of one pixel.
Consequently even without scaling you have resampled the image across a grid that doesn't coincide with the original image data, causing all pixels to be a bit off. It's just the right-hand edge is the most obvious case, since the resampling leaves you with a partial transparency here. But look at eg the two rows of purple pixels in the border: they're not the same, because your vertical alignment is off as well, causing a small amount of colour from the grey border below it to bleed into the lower row of purple.
Ok I actually figured it out this time. Cocos2D adds a bit of antialiasing to CCTextures. To stop it from doing this you need to call this:
[[mySprite texture] setAliasTexParameters];
to turn it back on you call this:
[[mySprite texture] setAntiAliasTexParameters];