I decided to have a play with XNA for Windows Phone 7, and for my first game, I need to take an image and split it up into square sprites, so the image essentially becomes a sprite sheet. The original image will likely be too large or small for the screen, so I've done the following to work out how to apply a scale such that it fits on the screen, but without any gaps showing (so one dimension may go beyond the screen).
Texture = content.Load<Texture2D>(assetName);
var width = Texture.Bounds.Width;
var height = Texture.Bounds.Height;
var widthDifference = width - screenWidth;
var heightDifference = height - screenHeight;
if (widthDifference < 0 || heightDifference < 0)
{
if (widthDifference < heightDifference)
Scale = (float) screenWidth/width;
else
Scale = (float) screenHeight/height;
}
else
{
if (widthDifference > heightDifference)
Scale = (float) screenWidth/width;
else
Scale = (float) screenHeight/height;
}
if (Scale < 0)
Scale = Scale*-1;
But next I need to generate sprites from this image that fill the screen neatly in a grid. I guess my main question is that when I call my draw method on each sprite, does the scaling apply to the original sprite sheet, or just to the sprite itself after taking its texture from the sprite sheet?
If it's the latter, I'm a little confused about how best to scale the sprite sheet before building my individual sprites. I may end up actually first resizing the image to exactly match the screen dimensions to make life easier, but this seems a little heavy handed.
Any suggestions would be most welcome!