Hey you all š
I'm trying to have some movement in my Menu Screen and I noticed that Control Nodes seem to have very jittery movement. I guess they only move on full integers and ignore fractions? Is there something I can do to disable this behaviou.
I attached a video which maybe explains my problem better:
On the left I have a Sprite2D and on the right a TextureRect, they both get moved by the same code, but the right one is very jittery. Seems to be also a problem with Label ( and therefore my assumption: all control nodes)
#Control Nodes have jittery movement
1 messages Ā· Page 1 of 1 (latest)
In case anyone encounteres the same problem, here is an answer from ChatGPT that helped.
TLDR: Use a Node2D for movement and a Control Node as child š
Can you help me with Godot 4.3?
You're correct in observing that Control nodes, like TextureRect, have their position properties (rect_position) quantized to integer values by default. This can cause the stuttering effect you're seeing when moving them, especially in contrast to Node2D-based nodes like Sprite2D, which can move smoothly using floating-point values.
Why does this happen?
Control nodes are primarily used for UI elements, and as such, they are optimized for pixel-perfect positioning. The default behavior rounds the position to the nearest integer to avoid sub-pixel rendering issues that can cause blurriness in UI elements. However, this can cause the movement to appear stuttery when animating the position in a way that requires smooth transitions.
Solutions
1. Use rect_position with floating-point values (workaround)
While Control nodes round the rect_position to integers, you can manually set the position in a way that attempts to preserve the sub-pixel movement by directly modifying the rect_position each frame:
extends TextureRect
var offset: float = 0.0
func _process(delta: float) -> void:
offset += delta * 100.0 # Adjust speed as needed
rect_position.x = sin(offset) * 100.0 + 200.0 # Example sine wave movement
This won't fully prevent the rounding, but it might help reduce the visible stuttering depending on your specific setup.