XNA beginners guide ported to Windows Phone 7

We had our first meeting with the Guatemalan .NET Developers community about XNA, I found an old example that Microsoft made many years ago, it is a XNA beginners guide and it shows how to make a 3D video game for PC with a simple missile launcher and some enemy ships you can destroy and I ported it to Windows Phone 7, you can download the example here.


Other resources:


How to fit a sprite into a fixed size rectangle?

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

Original Size
  • 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:

Original Size
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.