Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« A Career in Windows Phone Programming | Main | Windows 8 is a Mullet »
Thursday
Aug022012

MonoGame Demo

screenshot_08022012_142049

Last week I discovered how MonoGame is making it possible to write XNA games for the Windows 8 Metro environment. And I managed to draw a blue screen, which was nice enough, but not much of a basis for a game. So today I thought I’d make a sample project that had all the bits that you need to make your own game, including art assets, using the touch panel, using the accelerometer, drawing text and making sounds.

I’ve made a single, one-stop, demo that does all these things. It also includes the source of the MonoGame code as part of the project. I’ve found this to be quite useful when working out how the XNA implementation works. If you download the zip archive you should have everything you need. Here is how to get started.

Pre-Requisites

You will need three things before you can move any further:

  • Windows 8 Release Preview – this is where you run everything
  • Visual Studio 2012 Release Candidate for Windows 8 – this is where you build your program
  • Visual Studio 2010 for Windows Phone – this is where you create the XNA resources that you want to add to your game

Getting the Files

To get started just download the file from here. This is around 22MB. Before you unzip the file it is a good idea to Unblock it. This will stop Visual Studio from giving you warnings when you open any of the projects. To unblock the file you just have to right click on the file where you have download it, select Properties from the context menu and then click Unblock and then OK as shown in the badly highlighted screenshot below.

image

Then unzip the files. There are quite a lot of them. Once you have completed the download you will have the whole MonoGame framework and my little test project. Open the folder and find the Visual Studio Solution “MonoGame.Framework.Windows8” and open it. Make sure you open it with Visual Studio 2012 Release Candidate. If you double click the solution you will probably start up the wrong version of Visual Studio (I do) which doesn’t end well.

Running the Sample Program

The solution contains a project called Test Project which runs a port of a Windows Phone demo I wrote that lets you draw lines of dots on the screen using your finger. The dots that you draw will also fall down the screen in a way that is controlled by the accelerometer. You can clear the dots by double tapping on the screen, the game will make a “Ding” sound when you do this. The game also writes some text on the screen.

Resources and Fun

The MonoGame XNA part of things works very well, apart from content. At the moment there is no way of getting Visual Studio 2012 to pre-process XNA content for use in a game. We get around this by creating a Visual Studio 2010 XNA project and using it to produce the xmb files that are read by the content manager when the game runs. The content in the sample program came from existing XNA projects that I had around the place. If you are migrating an XNA game onto Metro you can do the same. The tricksy bit is where you put the xmb files for the game to use. I had no success adding them to the Visual Studio project, instead I had to put the xmb files in the specific directory read by the game when it runs.

image

Here you can see the path to the AppX\Content folder where I put the XMB files for the sample game. These include the two textures, the font and the ding sound file. If you want to add more content to your game, just drop your files here and then refer to them in the program as you would in any other resource:

protected override void LoadContent()
{
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);
demoTexture = Content.Load<Texture2D>("DemoArtwork"); demoRectangle = new Rectangle(0,0,GraphicsDevice.Viewport.Width,
GraphicsDevice.Viewport.Height); smudgeTexture = Content.Load<Texture2D>("Smudge"); font = Content.Load<SpriteFont>("MessageFont"); dingSound = Content.Load<SoundEffect>("ding"); }

You should be able to use my TestProject as the basis of anything that you fancy making.

Reader Comments (6)

Many thanks, Rob. You are a star.

I'm very much looking forward to when Microsoft's answer to Laurel and Hardy (aka Rob Miles and Andy Wigley) do for WP8 development what they did for WP7 development, namely an excellent set of videos explaining how it's done.
August 2, 2012 | Unregistered CommenterBrianT
Epic !

I had tried Patrick Godwins guide, which worked once to start with, then kept getting problems.

Note I only have a Desktop, so had to Run your Test project in the VS Windows 8 Tablet Simulator. I commented out Accelerometer code, as the Tablet Simulator does not seem to support the Accelerometer yet (As far as I can work out)

I could then play Smudges when Simulator in Touch Mode. But could not get the Dings and clear to work, as I haven't sorted out Double Touch on the Simulator.

Thanks for working out the Content bit. I wonder if this MonoGame build supports import of 3D Meshes and .X models when compiled into .xnb. I believe the MonoGame team were still working through the 3D support.

But I am ready to roll Now ! So Many Thanks for this guidance.

Jules
August 3, 2012 | Unregistered CommenterJules
i get this error while trying to debug the project:

A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code
The thread '<No Name>' (0x828) has exited with code 0 (0x0).
The program '[4932] TestProject.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
August 11, 2012 | Unregistered Commentersanjan
Rob

Glad you have tried MonoGame looking forward to what your students can do with existing WP7.5 and Xbox XNA developments in regards to porting them to Windows 8 Apps.

Lots more details about MonoGame at http://blogs.msdn.com/b/uk_faculty_connection/archive/2012/08/01/xna-developers-and-windows-8.aspx and generally gaming tips for Windows 8 at http://blogs.msdn.com/b/uk_faculty_connection/archive/2012/07/08/windows-8-metro-style-gaming.aspx
August 21, 2012 | Unregistered CommenterLee
Been a long time since the last post...

I was able to deploy the app to my Surface RT after some messing about with the project. I commented out the sound effect ding, it threw an exception no matter what environment I was debugging. I also created a Content folder in the project and moved the xnb files to that folder. Each was marked as Content, do not copy. I am not entirely sure why that worked but in the end the resources are getting deployed properly. Having the files in the Assets folder did not work.

There are a couple of bugs in the display of the smudges, the background constantly falls off the bottom of the screen and reappears at the top.

Regardless of the issues, this was a great demo and has helped me move a little closer to figuring out what the heck to do with my Surface RT.

Scott
November 25, 2012 | Unregistered CommenterScott
My bad, I am an idiot. The scrolling background was the accelerometer code in action. Should have realized that.
November 26, 2012 | Unregistered CommenterScott

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.