godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.74k stars 21.12k forks source link

Jittering pixel art backgrounds while in motion #82829

Closed giancarlo-padilla closed 1 year ago

giancarlo-padilla commented 1 year ago

Godot version

4.1.1

System information

Godot v4.1.1.stable - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 (NVIDIA; 31.0.15.3742) - Intel(R) Core(TM) i9-10850K CPU @ 3.60GHz (20 Threads)

Issue description

I have a ParallaxBackground Node that controls two different pixel art images. When I run my game, a very noticeable jitter occurs while they are in motion. It is intended to be a consistent horizontal movement with a fixed speed. I have tried adjusting the various project settings including:

Steps to reproduce

  1. Viewport Width: 408, Height: 255 | Window Width Override: 1280, Window Height Override: 800
  2. Stretch/Mode: canvas_items | Stretch/Aspect: keep
  3. Create a Node2D as root
  4. Create ParallaxBackground node as child of Node2D
  5. Add a ParallaxLayer as child of ParallaxBackground
  6. Add Sprite2D as child of ParallaxLayer using Texture/Filter: Nearest
  7. Attach script to ParallaxBackground node containing
    
    extends ParallaxBackground

var scroll_speed = Vector2(35, 0)

func _physics_process(delta): scroll_offset -= scroll_speed * delta


8. Use Motion/Mirroring
9. Set Motion/Scale to 1.0 or .75 (happens with both)
10. Run the scene

### Minimal reproduction project

[JitterReproduction.zip](https://github.com/godotengine/godot/files/12812877/JitterReproduction.zip)
dalexeev commented 1 year ago
giancarlo-padilla commented 1 year ago

My camera remains static, in fact I don’t even have a Camera2D in my scene. Could this still be the culprit?

dalexeev commented 1 year ago

My camera remains static, in fact I don’t even have a Camera2D in my scene. Could this still be the culprit?

The reason is not in Camera2D, but in the ratio of speed/acceleration of the background/objects and FPS. On a large pixel grid, jerky movement occurs if, for example, an object moves in the first frame by 1 pixel, in the second by 2, in the third again by 1, and so on. If the object moves the same number of pixels in each frame, then the illusion of continuous movement arises, even if the pixels are quite large.

giancarlo-padilla commented 1 year ago

My camera remains static, in fact I don’t even have a Camera2D in my scene. Could this still be the culprit?

The reason is not in Camera2D, but in the ratio of speed/acceleration of the background/objects and FPS. On a large pixel grid, jerky movement occurs if, for example, an object moves in the first frame by 1 pixel, in the second by 2, in the third again by 1, and so on. If the object moves the same number of pixels in each frame, then the illusion of continuous movement arises, even if the pixels are quite large.

Do you know of any fix? Or is the issue you linked the main hub for this problem. Sorry just a little confused because the one you linked exclusively talks about this being related to Camera2D. Edit: Also this is not a pixel perfect game, it just uses pixel art sprites.

Calinou commented 1 year ago

Do you know of any fix?

There is no way to fix this particular issue without changing your player or camera's movement speed. Mathematics are mathematics – you can't divide 5 by 2 and get an exact integer result, for instance.

Closing in favor of https://github.com/godotengine/godot-docs/issues/7774, as this is not an engine issue. See also https://github.com/godotengine/godot-proposals/issues/6389.

dalexeev commented 1 year ago

See also: