GET STARTED DEVELOPING FOR WINDOWS 8 WINDOWS PHONE AZURE WITH APP BUILDER
Many people were quite annoyed by the decision to not ship XNA as part of the Windows Metro Development space for Windows 8. The MonoGame project has stepped in and is building a cross-platform game solutions for XNA. Note that MonoGame is still under development, and you may hit some things that don’t work. I’m hoping to port a number of articles and code samples to MonoGame from XNA for Windows Phone, tracking the various issues I uncovered.
For a primer on MonoGame and setting up your environment, I suggest you review the resources at [ http://dfwiki.devfish.net/technology.Windows-8-Game-Development.ashx#_MONOGAME__0 ]. This is an evolving list of resources, which will grow over time. The YouTube Video [ http://www.youtube.com/watch?v=-ycmeVYm_gI ] on setting up your MonoGame environment, and Bob Familiar’s getting started blog series [ http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/01/windows-8-xna-and-monogame-part-1-overview.aspx ] are particularly useful.
When I started with XNA, one of my favorite articles, and still an example I use to show people how easy XNA is was the “How to: Create Your First XNA Framework Application for Windows Phone” article at http://msdn.microsoft.com/en-us/library/ff472340(v=VS.92).aspx . The how-to article will be our first proof point for XNA in Windows Metro. I take no credit for the code, merely making it work in Windows Metro via MonoGame.
Setting up your environment requires a number of steps.
Bob Familiar has done an excellent job documenting the setup of the environment in this blog post – [ http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/02/windows-8-xna-and-monogame-part-2-getting-started.aspx ]. After completing the steps documented you should have a new template available in Visual Studio 2012 for a MonoGame Metro Application.
In traditional XNA the Content Pipeline project is tasked with taking various fonts, audio assets, visual assets and turning them into XNA consumable files. These assets are stored in .XNB files, or XNA Binary Packages. The files may then be referenced by XNA programs. Note the files are not simple .zip extensions, and must be created.
Neither MonoGame or Visual Studio 2012 have a template or tools to create XNB files. So we must use Visual Studio 2010 to create our XNB files for us. Note: You must have Visual Studio 2010 with the Widnows Phone Developer Tools installed to create XNB files.
At this point we are ready to begin moving in the sample. Note the code is pretty much exactly the same code as is in the sample at [ http://msdn.microsoft.com/en-us/library/ff472340(v=VS.92).aspx ]. I’m reproducing the code here so you can have easy access to cut and paste without flipping back and forth. Also note we are not going into XNA fundamentals in this article. Please reference the resources in the original MSDN article or head over to http://bit.ly/devfish_wpgetstarted for some game programming resources.
Just like normal XNA, we’re going to add variables, load graphics and sound via LoadContent, Draw our objects in the Draw loop, and update the position of the graphic objects in the Update loop.
Vector2 spriteSpeed1 = new Vector2(50.0f, 50.0f);
Vector2 spriteSpeed2 = new Vector2(100.0f, 100.0f);
The default MonoGame template at this time does not automatically have an import for the SoundEffect namespace.
protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);
texture1 = Content.Load<Texture2D>("PhoneGameThumb");
texture2 = Content.Load<Texture2D>("PhoneGameThumb");
soundEffect = Content.Load<SoundEffect>("Windows Ding");
spritePosition1.X = 0;
spritePosition1.Y = 0;
spritePosition2.X = graphics.GraphicsDevice.Viewport.Width - texture1.Width; spritePosition2.Y = graphics.GraphicsDevice.Viewport.Height - texture1.Height; sprite1Height = texture1.Bounds.Height; sprite1Width = texture1.Bounds.Width; sprite2Height = texture2.Bounds.Height; sprite2Width = texture2.Bounds.Width;
protected override void Draw(GameTime gameTime)
// Draw the sprite.
spriteBatch.Draw(texture1, spritePosition1, Color.White);
spriteBatch.Draw(texture2, spritePosition2, Color.Gray);
void UpdateSprite(GameTime gameTime, ref Vector2 spritePosition, ref Vector2 spriteSpeed)
// Move the sprite by speed, scaled by elapsed time.
spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
int MaxX =
graphics.GraphicsDevice.Viewport.Width - texture1.Width;
int MinX = 0;
int MaxY =
graphics.GraphicsDevice.Viewport.Height - texture1.Height;
int MinY = 0;
// Check for bounce.
if (spritePosition.X > MaxX)
spriteSpeed.X *= -1;
spritePosition.X = MaxX;
else if (spritePosition.X < MinX)
spriteSpeed.X *= -1;
spritePosition.X = MinX;
if (spritePosition.Y > MaxY)
spriteSpeed.Y *= -1;
spritePosition.Y = MaxY;
else if (spritePosition.Y < MinY)
spriteSpeed.Y *= -1;
spritePosition.Y = MinY;
BoundingBox bb1 = new BoundingBox(new Vector3(spritePosition1.X - (sprite1Width / 2), spritePosition1.Y - (sprite1Height / 2), 0), new Vector3(spritePosition1.X + (sprite1Width / 2), spritePosition1.Y + (sprite1Height / 2), 0));
BoundingBox bb2 = new BoundingBox(new Vector3(spritePosition2.X - (sprite2Width / 2), spritePosition2.Y - (sprite2Height / 2), 0), new Vector3(spritePosition2.X + (sprite2Width / 2), spritePosition2.Y + (sprite2Height / 2), 0));
Hit F5 / Debug go and run the app to the local machine or the simulator. The boxes should bounce off the walls and make a ding when they cross. Stop the debugger when you wish to stop the app, or hit Alt-F4.
So we’ve now used MonoGame to do a very simple proof of concept for XNA on Windows Metro. Hopefully in some future articles, we can explore moving some of the other working tutorials out there into MonoGame and seeing how they fare. The MonoGame initiative looks very strong, and I’m excited to see it being used to port XNA based games to Windows 8 Metro.
So should i create the game in Visual studio 2010 to make sure the content pipeline is correct?
@question - You don't have to have VS2010 installed now. The Windows Phone 8 SDK has an xna game template in it. Install VS2012, then install the Phone 8 SDK. Use the XNA template inside the XNA Game Studio under Visual Studio 2012. Good luck and have fun!
@jhealy it's possible to do it with only VS2010 ?
I tried this and the UpdateSprite never executes?