I am starting learning C# and XNA, and I want to display an animated sprite (moved by my keyboard).
I've got this sprite file:
To display only the part I need, I use this code:
Rectangle cuttedSprite = new Rectangle(
this.W * (int)this.mCurSprite.X,
this.H * (int)this.mCurSprite.Y,
this.W,
this.H
);
spriteBatch.Draw(this.mSpriteTexture, this.mPosition, cuttedSprite, Color.White);
But my problem is that the rendered image is blurred after moving:
I tried to fix this by changing the SamplerStates
, but nothing changed. Does anyone have an idea to help me?
Round the position of the sprite to the nearest integers.
If the destination rectangle of the sprite is offset by less than a pixel, the sampler in the pixel shader will calculate the color by interpolating between the neighbouring pixels.
Another option is changing the filter method of the sampler to nearest-neighbour interpolation. You can do that by specifying a SamplerState.PointWrap
or SamplerState.PointClamp
when calling SpriteBatch.Begin
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With