Geeks With Blogs

News

Let's Meet!

My Office Hours
profile for borrillis on Stack Exchange, a network of free, community-driven Q&A sites
Mathoms There and back again... a blogging story.

Overview

There are several series from fellow Microsoft Evangelists on using MonoGame for your Windows 8 Store apps. I don’t want to duplicate what they have already done, so instead I’ll refer you to them below. These articles should give you a good start on using MonoGame to build your next game for Windows 8. Go ahead and read through these articles before continuing, I’ll be waiting for you after the fold. Smile

from Bob Familiar :

Windows 8, XNA and MonoGame – Part 1, Overview

Windows 8, XNA and MonoGame - Part 2, Getting Started

Windows 8, XNA and MonoGame - Part 3, Getting Windows 8 Store Ready

and Tara Walker,

Windows 8 Game Development using C#, XNA and MonoGame 3.0: Building a Shooter Game Walkthrough – Part 1: Overview, Installation, MonoGame 3.0 Project Creation

Windows 8 Game Development using C#, XNA and MonoGame 3.0: Building a Shooter Game Walkthrough – Part 2: Creating the Shooter/Player Asset of the Game

Windows 8 Game Development using C#, XNA and MonoGame 3.0: Building a Shooter Game Walkthrough – Part 3: Updating Graphics using Content Pipeline with MonoGame

Great, now you have enough background to dive a little deeper into MonoGame using Visual Studio 2012. What I want to show you in this post is how to make using MonoGame a little easier and more like what you may be used to if you are an XNA Game Studio 4.0 user.

Both Bob and Tara mention the fact that MonoGame currently does not have a build-time implementation of the Content Pipeline. In other words, you have to use the XNA GS 4.0 Content Pipeline projects in order to build your content. Building you content will take you images and other assets and transforms them into files with the .xnb extension.

Nearly every article or post you will find on the internetz will have you either use VS 2010 or VS 2012 with the Windows Phone SDK to build your content, then manually copy the content into your Windows 8 Store project so it can be found by the MonoGame content pipeline at runtime. To say the least this is a tedious, error prone and disruptive part of the development process.

There is a better way, and you will not need VS 2010 anymore, unless you are converting an existing XNA GS 4.0 project, which is a topic I’ll cover in a later post. With a few minor changes to your MonoGame project file, you can get your content to build and be placed in the correct folder for proper deployment.

The unfortunate part of this at the moment, is that this recipe will not work for the Express Editions of Visual Studio. I’m working on a post that will explain this and provide the best workaround that I can, stay tuned.

Ingredients List

Make sure you have the following products installed :

Recipe

  1. Create new MonoGame project and solution

    1. Open Visual Studio 2012
      image

    2. Create a new MonoGame Project

      1. File –> New –> Project [CTRL-SHFT-N]

      2. Select “MonoGame Game” from the Visual C# / MonoGame  category

      3. Give your Game Project a name, folder and solution name
        image

      4. Click “Ok” to create your game project

  2. Add Empty XNA Content Pipeline Project

    1. File –> Add –> Project

    2. Select the “Empty Content Project(4.0)” template from the Visual C# / XNA Game Studio 4.0 category

    3. Name the project “Content”
      image

    4. Click “Ok” to create your new content project

    5. Modify the Content Root Directory
      When the content builds, it will build into the output folder of the referencing project ( which will be the MonoGame project ). In XNA the game assembly was at the root and the content was in the Content folder under the output folder.
      In Windows 8, the application has to be packaged before it can be deployed, so the content has to be put into the packaging folder to be properly deployed. The packaging folder is called “AppX” and exists under the output folder.

      1. Select the Content Project in Solution Explorer

      2. In the Properties window, change the “Content Root Folder Property” from “Content” to “AppX/Content”
        image

  3. Add some test content
    New to Visual Studio 2012 is the ability to create game assets from within the IDE itself. We’ll use this feature to create a texture to test with.

    1. Right-Click the Content Project

    2. Add –> New Item[CTRL-SHFT-A]

    3. Select “PNG Image (.png)”
      image

    4. Click Add

    5. Use the image tools to draw something in the new image.
      image

    6. Save your Changes [CTRL-S]

  4. Modify MonoGame project file
    Now we need to hook the Content project to our MonoGame project so that building the MonoGame will build our content.
    image

    1. Unload the MonoGame project

      1. Right-Click the MonoGame Project

      2. Select “Unload Project”

    2. Edit the MonoGame Project File

      1. Right-Click the MonoGame Project

      2. Select “Edit MyMonoGame.csproj”

    3. Add XNA Build Properties
      Add the folowing properties the the first PropertyGroup element in the MyMonoGame project file
          <XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
          <XnaPlatform>Windows Phone</XnaPlatform>
          <XnaProfile>Reach</XnaProfile>

      image

    4. Add XNA Content Project Reference
      Now scroll to the bottom of the file and add the following lines before the last Import element.
        <ItemGroup>
          <ProjectReference Include="..\Content\Content.contentproj">
            <Name>Content</Name>
            <XnaReferenceType>Content</XnaReferenceType>
            <Project>{DE6937C4-6E2F-4C83-A39B-F5E2305610C9}</Project>
          </ProjectReference>
        </ItemGroup>
      image

    5. Add the XNA Content Pipeline targets
      Finally, after the last Import element add the XNA Content Pipeline targets import which will extend the build process and allow the content to be built with the Game project
        <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\v4.0\Microsoft.Xna.GameStudio.Content.targets" />

      image

    6. Reload the Project

      1. Save and close the currently open csproj file [CTRL-S] [CTRL-F4]

      2. Right click the MonoGame project in Solution Explorer

      3. Select “Reload Project”
        image

  5. Write some test code
    At this point everything should be wired up properly to build and deploy the project and content together. Lets make a few changes to our game class to see if it is all working properly.

    1. Open the Game1.cs file
      image

    2. Add a Texture2D field
      Texture2D _testTexture;
      image

    3. Load the Texture2D asset into the field
      In the LoadContent method after the TODO comment add:
      _testTexture = Content.Load<Texture2D>("Image1");
      image

    4. Display the Texture2D on the screen using SpriteBatch.
      In the Draw Method, after the TODO Comment but before the base.Draw call:
      _spriteBatch.Begin();
      _spriteBatch.Draw(_testTexture, new Rectangle(100, 100, 100, 100), Color.White);
      _spriteBatch.End();

      image

  6. Build + Test
    You know what to do…[F5]
    image
    If you have problems and need to make a few changes, sometimes it appears that they don’t seem to take. In that case try doing a clean then rebuild.

Wrap Up

With these changes in place, you can now enjoy the edit, build, deploy, test cadence that you were used to with XNA Game Studio. No longer do you need to switch between two instances of Visual Studio and manually copy files into the packaging folder.


Generation App: Getting You There

Generation_App_Logo

We are here to help you get your app on Windows. Here is how you can gain an advantage and stand out from the crowd through the programs we’re offering, all for free:

Generation App

  • Design Consultation
  • Technical Consultation
  • Online training and tips from insiders

Posted on Thursday, January 17, 2013 4:08 PM | Back to top


Comments on this post: A Recipe for Integrating the XNA GS Content Pipeline projects into your MonoGame projects

# re: A Recipe for Integrating the XNA GS Content Pipeline projects into your MonoGame projects
Requesting Gravatar...
Great "recipe" Michael!
Left by romeoxbm on Jan 17, 2013 5:42 PM

# re: A Recipe for Integrating the XNA GS Content Pipeline projects into your MonoGame projects
Requesting Gravatar...
Hi. Thank you for this solution but there is a problem. When you create app package content files aren't copied.
The same problem when trying to use remote debugging.
Left by krzysiek on May 09, 2013 10:31 AM

# re: A Recipe for Integrating the XNA GS Content Pipeline projects into your MonoGame projects
Requesting Gravatar...
Hi There! our family simply love your terrific site thanks and please keep on it
Nasdaq
Left by ray12 on Jun 09, 2013 5:12 AM

# re: A Recipe for Integrating the XNA GS Content Pipeline projects into your MonoGame projects
Requesting Gravatar...
Thank you very much for this! I'm using Visual Studio 2013 and the attribute 'style' is no longer used, or needed. Other than that, I resolved my content issues and were good!

Thanks!
Left by dcegames on Mar 07, 2014 10:35 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Cummings | Powered by: GeeksWithBlogs.net | Join free