I'm developing a 2D game, and I'm striving to create a nice blocky low-res appearance for the game, yet allow it to be played at variable resolutions. So, I've researched resolution independency and have a nice system in place to have my game rendered at 640x480 to a RenderTarget2D, and then have the RenderTarget blown up on the back buffer. Anybody that's looked into this knows that by default scaled images will be antialiased, and to disable that, change the SampleState to PointClamp. So, I've done that, but now I'm having this issue where my sprites aren't upscaling properly. Certain pixels are becoming particularly chunky where they shouldn't be, and I'm not sure what the cause of this behavior is, and I haven't been able to find any documentation of anybody else having this issue, can anybody offer any insight?
The last image illustrates the image rendered in game at 2X the original size. A 2:1 ratio should be a pretty straightforward scale to render, but if you look closely, there are some pixels that are at half size the others.
Edit #2: Here's some code regarding the scaling.
First, the game is captured by the render target at 640x480 resolution, then it is drawn at the back buffer's resolution (in the second image, reslution is 800x600, in the third image, resolution is 1280x960, I haven't messed with alternate aspect ratios yet).
graphicsDevice.SetRenderTarget(RenderTarget);
spriteBatch.Begin();
spriteBatch.Draw(Texture,
new Rectangle((int)location.X, (int)location.Y, frameWidth, frameHeight),
new Rectangle((int)spriteLocation.X, (int)spriteLocation.Y, spriteWidth, spriteHeight,
Color.White,
0f,
Vector2.Zero,
effect,
.826f);
spriteBatch.End();
graphicsDevice.SetRenderTarget(null);
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null);
spriteBatch.Draw(RenderTarget, new Rectangle(0,0, backbufferWidth, backbufferHeight), Color.White);
spriteBatch.End();
Edit #3: Code involving the sprite's height and width. First, in the class that my monster inherits from, is this little method that runs in the base class' Update() method. It just makes sure that if I have animations with non-uniform sizes, that the sizes are updating properly.
protected void UpdateFrameSizes()
{
frameWidth = animations[currentAnimation].Frames[animations[currentAnimation].currentFrame].SizeAndsource.Width;
frameHeight = animations[currentAnimation].Frames[animations[currentAnimation].currentFrame].SizeAndsource.Height;
}
Then, just to make sure that the Width and Height were correct in his animation class, I checked those:
idleFrame1 = new AnimationFrame(Texture, new Rectangle(154 * 0, 107 * 0, 154, 107), 1f);
idleFrame2 = new AnimationFrame(Texture, new Rectangle(154 * 1, 107 * 0, 154, 107), 1f);
idleFrame3 = new AnimationFrame(Texture, new Rectangle(154 * 2, 107 * 0, 154, 107), 1f);
All looks correct here, I even went to the source image and counted the pixels (Yes, I know, his sprite sheet's dimensions are weird, but they're accurate).
And then this data is all used in Edit #2's code snippet during the draw method.