Disable camera pixel snapping, while keeping sprite pixel snapping

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By oli4king

So I have 2 options I’ve found to zoom:

  • use shrink = 4 in the project settings,
  • use camera zoom = 0.25 in the camera node

While the shrink option gives sprites a nice pixel perfect aligned look, it makes the camera (with custom smoothing) jitter, because the camera seems to snap to the pixels as well.

The camera zoom option removes any jitter, but causes the sprites to not align with the pixel grid anymore, and thus causes some weird quarter pixel lines and stuff, which i’d like to avoid.

So, does anyone know a way to get the best of both worlds??
pixel snapping for sprites, but allowing the camera to move at sub pixel increments.

thanks in advance


:bust_in_silhouette: Reply From: oli4king


I figured it out.

so first
Project setting: stretch = 1
Camera: zoom = 1

Make a new scene:
-ViewportContainer (vpc)
–Viewport (vp)
— scene with your camera (sc)

vp: size = the size you want (viewport size/zoom factor + 1 to remove ugly lines on the sides)
vpc: scale = upscaling you want

camera: script:
keep a position variable (pos)
all smoothing goes into this var
for the actual position
camera.position = floor(pos)

vpc: script
var x = cam.pos.x - cam.position.x
var y = cam.pos.y - cam.position.y
rect_position.x = -int(floor(x * 4))
rect_position.y = -int(floor(y * 4))

That’s it

Hope this helps anyone with the same problems.