Click here to Skip to main content
15,867,568 members
Articles / Productivity Apps and Services / Sharepoint

MonoGame Content Project Tool Walkthrough

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
29 Aug 2016CPOL6 min read 8K   2   5
MonoGame Content Project Tool Walkthrough

To accompany the video project for the Content Project/pipeline tool, this blog post will also show you all the features of the MGCB tool, along with a few tips and tricks.

The video for this post can be found here if you prefer to watch a video:

This and more content can be found on my dedicated MonoGame channel here: http://bit.ly/darksideofmonogame

Content Projects with XNA –> MonoGame

In the XNA days, to manage content, we had a separate project type (The Content Project) which allowed us to store the assets for our project in one place. It also gave us access to the Content Pipeline, an arguably very powerful framework for managing the importing and consumptions of those assets:

image

The content project, referenced in the XNA game solution using a Content reference.

Did you know?
You can still Create / Manage and Edit XNA solutions today with Visual Studio 2013 / 2015 using the awesome MXA project. Just install the package and XNA will still live on and is still deployable.

http://mxa.codeplex.com/releases

Now MonoGame also has the same setup, you can create Content Projects using the MonoGame Content Project tool and reference them in the same way as XNA did:

imageimage

The MonoGame Content reference which links to the MonoGame Content Pipeline

The only main difference between the two methods is that MonoGame uses a separate tool rather than an embedded project, so that the tool cam be multi-platform and managed / updates separately. Apart from that, nothing has changed, how you load your content before works the same today.

If you want, you can still add compiled .XNB files in to your project, or even add the raw files (MonoGame supports both ways) and load them both the same way:

image

However, you will lose the power of the content pipeline and you will manually need to manage compression and cross-platform compatibility of the assets. All of which are included with Content Projects by default.

Getting Started with the Content Project / Pipeline Tool (MGCB)

As with everything MonoGame (and most open source projects in general), you have the choice for how to use the Content Tool, you can:

  • Use the pre-built Content Project that comes with any new MonoGame project as is.
  • Create Content Projects separately and reference them manually.
  • Forget this content pipeline stuff and do it yourself. (You could also drop MonoGame and write your game in C++, Assembly or JavaScript :D)

Whichever path you chose with your MonoGame Content projects, you can manage them in the same way.

1: Create a Project

Either use the one new MonoGame Projects or create your own. Just open the MonoGame Content Project tool and do file / new:

NewContentProject

When creating a new project, it is best to:

  • Place it in a folder called Content. Not mandatory but recommended.
  • Create the Content folder relative to or with your Game project, just so you don’t lose it. Again up to you.

2: Add Content

When adding content, you can either:

  • Add each file individually
  • Create new folders to store content in
  • Add entire folders, which will also add the content within that folder

AddingContent

When selecting existing files, you can opt to either copy the files into the Content Projects folder, or leave them in place and simply reference them. I would always recommend copying so that you keep all your games actual content in one place. Makes it easier to transport or publish to a source code repository as well.

3: Build and Test

One of the great features of the MonoGame Content Project tool is that you can build the content in the tool and see the debug output of that process. This helps you identify any content issues early on, especially if you are going down the advanced route and building your own content importers / processors (more on that later).

BuildContent

4: Add to Your Game Project

Once you have your project built and ready, you can add it to your MonoGame solution. The process is the same whether you use Visual Studio or MonoDevelop.

*Note, new MonoGame game Templates already come with a Content Project, so you can skip this step if it is already in your solution.

AddingReference

A few tips when adding the content reference manually to your project:

  • When adding the Content Project file, make sure it is stored relative to the content, else it will break the asset references. I recommend adding the project “As a Linked” file, that way it stays where it is. Alternatively, copy/move the content folder into your game project and then add normally. Just clicking OK will copy and MOVE the content project and may cause build errors if done wrong.
  • The other option to avoid the above is to just start with the Content Project that comes with new MonoGame projects, then there are no issues.
  • Double-clicking on the MGCB Content Project file will open the Content Project tool automatically.
  • After you have added the Content Project reference, REMEMBER to change the Build Action to a MonoGameContentReference, else it won’t build. Setting the action to this type makes the Build process launch the Content Builder using your content project and actually compiles your assets.

5: Load Content and Draw

Now this is no different to XNA, you simply Load your content and then Draw it to the screen. There is a lot more you can do with this, but simply using:

C#
Texture2D myKnight;

protected override void LoadContent()
{
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);

    // TODO: use this.Content to load your game content here
    myKnight = Content.Load<Texture2D>(@"Attack (1)");
}

protected override void Update(GameTime gameTime)
{
    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || 
                                 Keyboard.GetState().IsKeyDown(Keys.Escape))
        Exit();

    // TODO: Add your update logic here
    spriteBatch.Begin();
    spriteBatch.Draw(myKnight,Vector2.One);
    spriteBatch.End();

    base.Update(gameTime);
}

Will take your content and draw it to the screen. Simple!

Next Steps

Well, you now have your content, it is nicely packaged and ready for use in your game projects, what could be better?

Well, one thing that is absolutely awesome is that you can use the same Content Project for ALL your platforms, in fact the only time you may want to use more than one content project is if you are supporting vastly different resolutions (and need higher quality art). In general though, only one is needed.

Well, I say one, you can have as many Content Projects as you like, there is no limitation. Some games package assets per level, some have the types of art in different projects, just because it’s easier to manage that way, the choice is up to you.

The only thing that should not go in to a Content Project at this time are Xact Projects (audio master collections). You can store individual audio files like MP3s, WAVs and so on. But Xact is not supported fully yet. I believe you can add them manually to the project but I’ve not had reason to test that fully as yet. I will report back when I have more information.

Going Advanced

Now I mentioned earlier about creating your own Content Importers and Processors, these are what are known as Content Pipeline Extensions.

It’s a lot to go into fully here but Andy Dunn and Tom Spilman recorded a session with Microsoft to cover this which can be found here.

In the future, I’ll do a follow up session just to break down the essentials.

On With the Show

Right, I’m done with basic use of the Content Project. If you have any specific requests for subjects to follow this, then please leave a comment below or on my MonoGame YouTube channel (http://bit.ly/darksideofmonogame).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect ZenithMoon Studios
United Kingdom United Kingdom
Long-time game developer / IT maniac.
By day I architect, design, build and deliver enriching Mixed Reality solutions to clients, bringing the work of AR/VR to light in new and interesting ways, by night I Masquerade as the Master Chief of ZenithMoon Studios, my own game development studio.

At heart, I am a community developer breaking down lots of fun and curious technologies and bringing them to the masses.

I'm also a contributor to several open-source projects, most notably, the Reality Toolkit and all the services provided by the Reality Collective, The Unity-UI-Extensions project, as well as in the past the AdRotator advertising rotator project for Windows and Windows Phone.

Currently, I spend my time fulfilling contracts in the Mixed Reality space (primarily for an XR experience firm called Ethar), writing books, technically reviewing tons of material and continuing my long tradition of contributing to open-source development, as well as delivering talks, but that goes without saying Big Grin | :-D

Mixed Reality MVP, Xbox Ambassador, MS GameDevelopment Ambassador & Best selling author:

[Accelerating Unity Through Automation](https://www.amazon.co.uk/Accelerating-Unity-Through-Automation-Offloading/dp/1484295072/ref=rvi_sccl_3/262-0817396-1418043)
[Mastering Unity 2D Game Development] (https://www.packtpub.com/game-development/mastering-unity-2d-game-development)
[Unity 3D UI Essentials] (https://www.packtpub.com/game-development/unity-3d-gui-essentials)

Comments and Discussions

 
QuestionYouTube videos missing - but links are still visible Pin
Simon Jackson30-Aug-16 9:15
Simon Jackson30-Aug-16 9:15 
AnswerRe: YouTube videos missing - but links are still visible Pin
Simon Jackson31-Aug-16 22:29
Simon Jackson31-Aug-16 22:29 
QuestionNice Pin
BrunoPichon29-Aug-16 8:39
BrunoPichon29-Aug-16 8:39 
AnswerRe: Nice Pin
Simon Jackson30-Aug-16 9:11
Simon Jackson30-Aug-16 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.