Sprite is getting blurry

I'm starting to learn C # and XNA, and I want to display an animated sprite (moved by my keyboard).

I have this sprite file:

basic sprite

To display only the part that 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 blurry after moving:

blur problem

I tried to fix this by changing SamplerStates , but nothing changed. Can anybody help me?

+7
source share
2 answers

Complete the sprite position to the nearest integers.

If the sprite destination rectangle is offset by less than a pixel, then the sampler in the pixel shader will calculate the color by interpolating between adjacent pixels.

Another option is to change the filtering method of the sampler to interpolate the nearest neighbor. You can do this by specifying SamplerState.PointWrap or SamplerState.PointClamp when calling SpriteBatch.Begin .

+5
source

The easiest way: cast (int) Position.X and (int) Position.Y when the move button is released

0
source

All Articles