我为一个游戏创建了一张背景图,尺寸为300x135像素。当加载到我的游戏中时,我需要它从点(0,0)开始显示,它也确实是这样显示的:
position = new Vector2(0, 0);
然而我想把这张图片扩大到1200x540像素,但是我不太确定应该如何做,尽管我知道我应该使用Rectangle
或类似的东西。
这里是背景图片的组成部分:
Vector2 position;
Texture2D texture;
destinationRectangle
参数的SpriteBatch.Draw(...)
重载方法,你可以在其中设置大小。
destinationRectangle
类型: 矩形(Rectangle)
指定绘制精灵的目标位置(以屏幕坐标为准)的矩形。如果此矩形与源矩形大小不同,则会缩放精灵以适应其大小。
https://msdn.microsoft.com/zh-cn/library/ff433987.aspx
yourBatch.Draw(texture,
new Rectangle(position.X, position.Y, 1200, 540),
new Rectangle(0,0, texturesOriginalWidth, texturesOriginalHeight),
Color.White);