Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jittering pixel art backgrounds while in motion #82829

Closed
giancarlo-padilla opened this issue Oct 5, 2023 · 6 comments
Closed

Jittering pixel art backgrounds while in motion #82829

giancarlo-padilla opened this issue Oct 5, 2023 · 6 comments

Comments

@giancarlo-padilla
Copy link

giancarlo-padilla commented Oct 5, 2023

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:

  • Physics Jitter: Fix 0.0, 0.5, and 1.0
  • VSync On/Off
  • FPS Limit: Off/60
  • Snap 2D Transforms to Pixel: On/Off
  • Snap 2D Vertices to Pixel: On/Off
  • Ensuring proper resolution scaling (no non-integer scaling & no viewport window override)
  • Allow hiDPI: On/Off
  • Pixel Snap: On/Off
  • Windowed/Fullscreen
  • Stretch/Mode: disabled, canvas_items, viewport
  • Renderer: Forward+, Mobile, Compatibility
  • Moving Parallax "scroll_offset" code to: _physics_process() & _process()
  • Adding lawnjelly/smoothing-addon
  • Physics Ticks per Second: 60 & 120

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
  1. Use Motion/Mirroring
  2. Set Motion/Scale to 1.0 or .75 (happens with both)
  3. Run the scene

Minimal reproduction project

JitterReproduction.zip

@dalexeev
Copy link
Member

dalexeev commented Oct 5, 2023

@giancarlo-padilla
Copy link
Author

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

@dalexeev
Copy link
Member

dalexeev commented Oct 5, 2023

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
Copy link
Author

giancarlo-padilla commented Oct 5, 2023

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
Copy link
Member

Calinou commented Oct 5, 2023

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 godotengine/godot-docs#7774, as this is not an engine issue. See also godotengine/godot-proposals#6389.

@dalexeev
Copy link
Member

dalexeev commented Oct 5, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants