简体   繁体   中英

Monogame - Change the size of a sprite

I have created a background image for a game that is 300x135 pixels. When loaded into my game, I need it to start at point (0,0), which it does:

position = new Vector2(0, 0);

However I want to enlarge this image so it spreads to 1200x540 pixels, however I'm not quite sure how to do this, although I'm aware I'm meant to use a Rectangle or something similar.

Here are the componets for my background image:

Vector2 position;
Texture2D texture;

If Monogame truly mimicked XNA, there should be a SpriteBatch.Draw(...) overload with a destinationRectangle parameter where you can set the size.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM