If you have an image, you can draw a sprite with that image in a specific rectangle size. For instance, I have a menu background image of 480 x 320 pixels and the Windows Phone 7 screen is 480 x 800, if I draw it without specifying a sized rectangle, only the texture, position and color it would look like this:
ScreenManager.SpriteBatch.Draw(mMenuBackgroundSprite.Texture, mMenuBackgroundObject.Position, Color.White);
- mMenuBackgroundSprite.Texture is a Texture2D initialized with the image.
- mMenuBackgroundObject,Position is the position where that 2d object should appear in the WP7 screen, in this case is a Vector2D initialized as (0,0).
- Color.White indicates that is going to be drawn in full color without tint.
But if I specify a rectangle to fit the sprite like this:
ScreenManager.SpriteBatch.Draw(mMenuBackgroundSprite.Texture, new Rectangle(0,0, 800, 480), Color.White);
It would look like this:
Where “new Rectangle(0, 0, 800, 480)” defines a rectangle positioned in the coordinates x=0, y=0, with a size of 800 x 480 pixels to fit the whole screen.
*Made on XNA 4.0 with C# 2010 – Microsoft Visual Studio 2010 Express for Windows Phone.