1

我决定在 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;

但接下来我需要从这个图像中生成精灵,它们在网格中整齐地填充屏幕。我想我的主要问题是,当我在每个精灵上调用我的绘制方法时,缩放是否适用于原始精灵表,或者在从精灵表中获取其纹理后仅适用于精灵本身?

如果是后者,我对在构建我的个人精灵之前如何最好地缩放精灵表感到有点困惑。实际上,我可能最终会首先调整图像大小以完全匹配屏幕尺寸以使生活更轻松,但这似乎有点笨拙。

任何建议都将受到欢迎!

4

1 回答 1

1

您是说您的 spritesheet 图像比屏幕大,还是其中的单个精灵更大?

如果是前者,我认为这并不重要,因为您只会绘制表格的一部分(即您的个人精灵)。

如果是后者,那么只需使用图像编辑器缩放精灵表。

如果您使用的是,SpriteBatch那么您可以指定一个源矩形(纹理坐标)和一个目标矩形(屏幕坐标),这样您就可以在那里进行缩放。

于 2012-02-01T07:58:12.133 回答