我决定在 Windows Phone 7 上玩 XNA,对于我的第一个游戏,我需要拍摄一张图像并将其拆分为方形精灵,因此图像本质上变成了一张精灵表。原始图像对于屏幕来说可能太大或太小,所以我已经完成了以下操作来确定如何应用比例以使其适合屏幕,但没有显示任何间隙(因此一个维度可能超出屏幕)。
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;
但接下来我需要从这个图像中生成精灵,它们在网格中整齐地填充屏幕。我想我的主要问题是,当我在每个精灵上调用我的绘制方法时,缩放是否适用于原始精灵表,或者在从精灵表中获取其纹理后仅适用于精灵本身?
如果是后者,我对在构建我的个人精灵之前如何最好地缩放精灵表感到有点困惑。实际上,我可能最终会首先调整图像大小以完全匹配屏幕尺寸以使生活更轻松,但这似乎有点笨拙。
任何建议都将受到欢迎!