Jump to content
  • Advertisement
Sign in to follow this  

2D Sprites hard edges

This topic is 3405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!