prime31 / Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
MIT License
1.76k stars 355 forks source link

Batcher.PushSprite does not round Sprite destination #761

Closed conlanpatrek closed 1 year ago

conlanpatrek commented 1 year ago

Noticed this today. Looks like there is some code in the Texture2D signature that rounds texture position, presumably to avoid sub-pixel shifting.

The Sprite signature of the same method is missing this destination rounding, so when zooming in, sprites are splitting pixels constantly.

Steps to reproduce:

  1. Create a test scene with two entities, both sprites with pixel art.
  2. Zoom the camera in.
  3. use Mathf.Sin() to oscillate the position of one of the sprites back and forth in front of the other.
  4. make sure Batcher.ShouldRoundDestinations is set to true

Expected: The moving sprite snaps to the same pixel grid the stationary sprite is rendered on

Actual results: The moving sprite slides fluidly at screen resolution, splitting the pixel grid

conlanpatrek commented 1 year ago

https://github.com/prime31/Nez/blob/master/Nez.Portable/Graphics/Batcher/Batcher.cs#L676-L680 - the rounding check in the Texture2D implementation

https://github.com/prime31/Nez/blob/master/Nez.Portable/Graphics/Batcher/Batcher.cs#L846 - the method missing the round