Reputation: 2016
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?
Upvotes: 7
Views: 1049
Reputation: 1
The most easy is cast to (int)Position.X and (int)Position.Y when the movement button is released
Upvotes: 0
Reputation: 3745
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
.
Upvotes: 5