2D Sprites hard edges

Started by
3 comments, last by Fragsta 15 years, 3 months ago
I've got a few 2D textures which are to be resized, and when they do, they always lose their hard edges - usually, this isn't desireable but for the kind of game I'm making I'd like it if they did, actually. I made sure that if they were made bigger they would retain them by simply resizing the textures in photoshop and retaining the edges there, but now when some of them shrink, the thinner lines disappear. Does anybody have any ideas of how I can ensure hard edges are retained both for growing and shrinking of textures? Thanks :)
Advertisement
You could manually generate the mipmaps yourself. Use the .DDS file format to save the textures as that stores all the mipmap levels in it.

You can use the NVIDIA Texture Tools to do that.
You can either enable or disable anti-aliasing when resizing an image to a smaller size. When anti-aliased the outlines will probably be smoothed out. If you keep anti-aliasing disabled you will lose pixels on the outline.
You could restore the outline by creating a drop shadow behind the object. If you then duplicate the shadow a few times it will look less softened.
If you want a pixelated effect of sprite zoom, like older consoles games you simply set texture filtering to POINT.

If you use pixel shaders you can control texture filtering inside the .fx file like:

uniform texture sourceTex;sampler sourceSampler : register(s0) = sampler_state{    Texture = (sourceTex);    AddressU  =	CLAMP;		    AddressV  =	CLAMP;    AddressW  =	CLAMP;    MIPFILTER =	NONE;    MINFILTER =	POINT;    MAGFILTER =	POINT;};


If you don't use pixel shaders you can control texture filtering from XNA GraphicsDevice object inside the main Game class:

GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.None;


Note that 0 is the sampler used from SpriteBatch by default.
Please vote usefull replies.
Marco Sacchi
Coding is a challenge ... but solving problems is the fun part
My Blog - XNA Italian portal
Right, thanks for the tips everyone - turns out it wasn't what I thought it was though, it just wasn't drawing the entire texture... only the top left corner. I will probably need the advice at some point though so thank you :)

This topic is closed to new replies.

Advertisement