Hello Guest

Author Topic: Pixel tearing -- how do I solve it? How does tk2dSprite.MakePixelPerfect() work?  (Read 4600 times)

BlueLemming

  • Newbie
  • *
  • Posts: 3
    • View Profile
I'm having an issue with "pixel tearing" in my game. I'm using 2 test keys to move my character 0.01 pixels forward/backward and I can see my sprite tearing as it goes through decimal coordinates. I've tried running sprite.MakePixelPerfect() during Update, LateUpdate and directly after the functions that move the character 0.01 pixel at a time, yet I see no difference. So I'm not exactly sure what MakePixelPerfect() or how I am supposed to use it.

If MakePixelPerfect() isn't the answer, how would I solve this pixel tearing issue? I bought this asset hoping it would work but it seems it's incompatible with TK2D, but that's the effect that I'm aiming for.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
MakePixelPerfect scales it to match the camera, but if you're moving it 0.01 pixel at a time that isn't going to change anything (assuming you're running with 1:1 pixel - sprite texture ratio otherwise). If you want pixel level control your best bet is to decouple the graphics and set the positions snapped to the closest pixel yourself.

Edit - I don't know what that other asset  does.
« Last Edit: May 31, 2015, 05:17:22 pm by unikronsoftware »

BlueLemming

  • Newbie
  • *
  • Posts: 3
    • View Profile
I've tried snapping but that affects the speeds of my character, which are all float values. So my walking speed of "1.25" is essentially snapped down to "1".

The asset I referred to basically just handles the drawing of the sprite rather than snapping the transform. It keeps the "real" position (transform), but snaps the drawing of the sprite. That way my speeds and position aren't affected but the sprite isn't teared from a half pixel or whatever. I was hoping 2DTK had a native way of handling that.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
tk2d doesn't do that, it would be far too slow to snap geometry every frame. I find its much easier to simply maintain your own "position" field in your behaviour and update that vs Unity position, and you can assign the unity position snapping any which way you like - its way way more efficient and just works.