@berarma said: Where would I put that code?
Ideally right after the movement of the KinematicBody2D, so after any movement of the node, the Sprite nodes get updated as well. You could also put it at the end of _physic_process
and it'd probably also work.
I think that's what's already happening. The physics work with the floats, and when rendering it gets rounded to the nearest pixel. And that's exactly the problem I'm trying to avoid or solve.
Two objects that are only 0.2 pixels apart can get rendered in the same pixel or 1 pixel apart depending on the exact position. If they're at (50, 50) and (50.2, 50.2) they will show at the same pixel, but if they're at (50.4, 50.4) and (50.6, 50.6) they will be at different pixel positions in the X and Y axes.
It's only an issue when an object is pushing or dragging one another, since the rounding is done after the interaction between objects.
Hmm, what you may want to do then floor
the value instead of rounding it, so positions (50, 50)
, (50.2, 50.2)
, and (50.6, 50.6)
all would be rendered as (50, 50)
. So instead of global_position.round()
you'd want to use global_position.floor()
.