0

Why do my texture's edges contain unwanted colored lines? Texture looks shifted by a part of a pixel.

user1306322
  • 8,561
  • 18
  • 61
  • 122

1 Answers1

0

Texture2ds can be seen as shifted or misplaced sometimes when you're not drawing the whole texture, but just a part of it via SourceRect parameter and the texture's position (Vector2) has nonintegral coordinates. It may look like undesired texels showing at its edges.

If you have a texture with 1px purple border, the actual image can appear with sligthly purple edges. You can avoid that by making the texture coordinates integral.

If this code causes trouble…

Texture.Position.X = 4.9876f; // 4.9876f is an example of actual value
Texture.Position.Y = 5.1234f;

…try adding a cast:

Texture.Position.X = (int)4.9876f;
Texture.Position.Y = (int)5.1234f;
user1306322
  • 8,561
  • 18
  • 61
  • 122