0
votes

I have a spritesheet with 2 sprites. Each sprite is 40x60. The total size of the image is 40x120. It looks like this (the red line is part of the 1st sprite). I'll tell you in a second why I added that.

enter image description here

It seems that for some reason, when trying to draw the second sprite, it will always take the last line of the previous sprite. I have drawn that red line to illustrate that.

This is my code that draws the 2nd sprite:

Rectangle rect = new Rectangle(0, 60, 40, 60); // Choose 2nd sprite
Vector2 pos = new Vector2(100, 100);
Vector2 origin = new Vector2(0, 0);

spriteBatch.Begin();
spriteBatch.Draw(mSpriteTexture, pos , rect, Color.White, 0.0f, origin, 6, SpriteEffects.None, 0.0f);
spriteBatch.End();

And this is how it looks when I run the program:

enter image description here

Any ideas what I'm doing wrong?

Note: For this example I'm using scale=6. I did this because it seems that when scale > 1 this problem will always happen. If scale = 1, it doesn't seem to happen all the time.

1
Have you tried using 61 at the Rectangle Y location when choosing the second sprite?Steven
That doesn't work. Sprites overlap even more.LEM
This problem is discussed here with some possible solutions: gamedev.stackexchange.com/questions/45764/…Monacraft
Did you try drawing with spriteBatch using destinationRectangle instead of scaling? Not guaranteeing a fix, just suggesting you try it to see if it works.Monacraft
Monacraft, thanks for the link and for the suggestion. It provided some new ideas to try but it seems the author never found a solution. I had already tried most of them. Using PointClamp improved things a lot, but the problem still happened from time to time. I ended up adding some tile space and the problem is gone. Not the best solution but I fixed it for now.LEM

1 Answers

1
votes

Had the same issue. Used SamplerState.PointClamp in my spriteBatch.Begin - call to fix it

It looks like this: (MonoGame 3.6 tho)

SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null, viewMatrix);