Search code examples
c#xnaspritetexture2dblurry

Sprites blurry when enlarged


In XNA I am trying to create a game using old style Super Mario sprites, but if I try to make them bigger, they get very blurry. I have tried saving the PNG sprites as nearest neighbor, bicubic, and bilinear in photoshop, but they all appear equally blurry. I have also tried compressing the PNG online, which also didn't help.

My knowledge of XNA is somewhat basic, so unless your answer is code I can simply copy paste into my 'main' class, please explain how to use it.


Solution

  • In your draw-function you should only need to change one row of code.

    Where you call spritebatch.Begin(); instead call

    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
    

    This will set your "GraphicsDevice" to render textures without interpolating the colors between whole pixels when the sprites get zoomed.

    One other thing that you could do is to use a rendertarget with the resolution you want the game to "emulate" , draw everything on the rendertarget and finally draw that to the screen. This is a bit out of the scope of this question but it is ideal if you want to create a genuine oldschool experience.