Monogame - 改变精灵的大小

Monogame - Change the size of a sprite

我为一款 300x135 像素的游戏创建了背景图片。当加载到我的游戏中时,我需要它从点 (0,0) 开始,它确实如此:

position = new Vector2(0, 0);

但是我想放大这张图片,让它扩展到 1200x540 像素,但是我不太确定该怎么做,尽管我知道我打算使用 Rectangle 或其他东西相似。

这是我的背景图片的组件:

Vector2 position;
Texture2D texture;

如果 Monogame 真的模仿了 XNA,应该有一个 SpriteBatch.Draw(...) 重载和一个 destinationRectangle 参数,您可以在其中设置大小。

destinationRectangle
Type: Rectangle
A rectangle that specifies (in screen coordinates) the destination for drawing the sprite. If this rectangle is not the same size as the source rectangle, the sprite will be scaled to fit.

https://msdn.microsoft.com/en-us/library/ff433987.aspx

yourBatch.Draw(texture, 
               new Rectangle(position.X, position.Y, 1200, 540), 
               new Rectangle(0,0, texturesOriginalWidth, texturesOriginalHeight), 
               Color.White);