Sprites appear strangely distorted in game

Godot Version

4.2.2.stable.mono

Question

When I load the sprites in engine they look just fine, but when i run the game they may appear as if strangely distorted(as if rotated by a really small angle). Moving the camera fixes or breaks them. Maybe the camera stops between pixels or something? Anyway I tried everything i could think of - no weird properties of camera/scenes/sprites are checked, everything is set to rotation 0. The texture filter is set to nearest (both to the sprite and the project itself).
Any help would be welcome. Here are 2 shots of the sprite in engine and in game.
In game

In Engine

have you used a different from scale Vector2(1,1) ? OR try to reimport then using different compression modes/formats

Thank you for the reply! :slight_smile:
I am only using Vectro2(1,1) scale for sprites.
I tried reimporting the files with different filters, but nearest seems to work best. The format of the files is png and the sprites themselves are made in pixel art software so they are 1 color (red in this case) for the outline of the houses and another that signifies opacity. There are no other colors or gradients and such.

Camera movement
I am starting to suspect that my camera movement is messing up somehow. In the gif above you can see how the sprites change when i move around. The scale of the camera is also (1, 1) here. After each move some houses appear more distorted while others look better.
The camera is attached to a CharacterBody2D and I am using slip and slide to move around. I am guessing that when the CharacterBody2D stops “between pixels” (example Position = Vector2(3.41f, 17.87f)) some anti aliasing tries its best to patch things up and these distortions occur. I will continue investigating tomorrow.

yes it could be because of it, you may try to add a delayed

var pos:=position
position=Vector2(floorf(pos.x), floorf(pos.y))

to round up position on end of camera movement

How does it look when you export the game or try it on a different computer? Usually, the editor player is terrible. It competes with all kinds of OS resources like mouse input while idle and monitor refresh rates.

Thank you for the suggestions! :slight_smile:

I first tried exporting the project and run it that way. There was no change from running it from the engine.
Then i implemented a check that rounds the position of the camera after moving and now the sprites behave a lot better. I still have the issue with one of the sprites and i will look into that. I think it is an issue with the size of the sprite (odd number of pixels) and when i place it in the game by code it might be placed between pixels.
The issue is still visible when i use a (0.5, 0.5) camera zoom, but it is reversed. The problematic sprite looks fine while the others are distorted.
I can only assume the main problem was the camera position and that i have to fix my placement code/ sprites.

I will update you guys when i manage all that.
Thanks again! :slight_smile:

For anyone with the same problem now or in the future these are the things I changed in order to fix the issue:

  1. Round the camera position to full pixel after moving
  2. All sprites are “doubled”. As in the minimum width of a line is 2 pixels and from there upwards I use only even number of pixels for width (2,4,6 …).
  3. Make sure the position of the sprites is rounded too.

I don’t believe that is the best solution, but that is the best I got for now.
Thank you to everyone for helping! :bowing_man:

And of course 5 min after posting my defeat youtube offered me the video that solved the issue with 1 click.

Project settings → Rendering → 2D → tick Snap 2D vertices to pixel

Everything looks perfect even with (0.5, 0.5) camera scale.

1 Like