Monogame - 更改精灵的大小

toa*_*lax 2 c# xna monogame

我为一个300x135像素的游戏创建了一个背景图像.当加载到我的游戏中时,我需要它从点(0,0)开始,它执行:

position = new Vector2(0, 0);
Run Code Online (Sandbox Code Playgroud)

但是我想放大这个图像,所以它扩展到1200x540像素,但是我不太清楚如何做到这一点,虽然我知道我的意思是使用Rectangle或类似的东西.

以下是我的背景图片的组件:

Vector2 position;
Texture2D texture;
Run Code Online (Sandbox Code Playgroud)

TyC*_*obb 7

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

destinationRectangle
类型: Rectangle
一个矩形,指定(在屏幕坐标中)绘制精灵的目标.如果此矩形与源矩形的大小不同,则将缩放精灵以适合.

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);
Run Code Online (Sandbox Code Playgroud)