0
votes

I'm new to the Monogame content pipeline tool, as opposed to XNA which would do the compiling you need on itself. So I may be having a pretty simple problem I fail to see a solution for. Here's my XML file:

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:ns="Microsoft.Xna.Framework">
  <Asset Type="Game1.Screens.SplashScreen">
    <SplashScreen>
      <Path>Images/Image1</Path>
    </SplashScreen>
  </Asset>
</XnaContent>

So I'm not entirely sure as of what <Asset Type="..."> wants as a value, but the debugger tells me there's an error there: Could not resolve type 'Game1.Screens.SplashScreen'. So it's a simple tutorial I was watching:

The Tutorial

There the person decided to teach on how to use XML serialization. So he was using XNA but most of this code should work on Monogame as well. Anyway, what he did was, add a new XML file to a folder, outside of the Content.RootDiretory and added his XML file in there. Since I've never released a project with Monogame yet, so correct me if I am wrong, but won't that XML file that's set to Copy always to output directory be user-viewable/editable? Or will it be compressed into XNB? Or perhaps it won't be even presented there? So that is the problem's root, now let's see the top:

Being unable to answer to myself whether the XML file will actually be presented in the final product's Content directory, I decided to use the Content pipeline tool and add the above XML file from there as I was sure that it would be converted into XNB. But now I get this error. And I don't know where am I wrong? Should I set the file's build action from the default Build to Copy the error disappears, but the XML file will be in my Content directory instead of the XNB one. Please advice.

Here's some more information about the SplashScreen class: It inherits from another class, GameScreen. It is inside the Screens, folder inside the project's folder. That's why I tried to use Game1.Screens.SplashScreen, where Game1 is the name of my project.

Thanks in advance!

1

1 Answers

1
votes

Your intuition is correct. The tutorial's version would have to ship the game with the xml file. But the Xna content pipeline can build it into a binary file for shipping your game and the runtime content pipeline can load it into your game.

when it loads it into your game, it needs to know what class the data will fit into so it can plug the data into an instance of that class

Class MyGameInitialConfiguration
{
  public string path; 
  /*
   other possible game settings can be added too
   public float heroPower;
   public string badGuyName;
  */
}

//then in the xml file

<asset type=MyGameInitialConfiguration>

Now, since the first thing the build process does when you hit run is build the assests (convert the fbx into xnb and the images into xnb and your xml into xnb), in needs to know what a "MyGameInitialConfiguration" is before you hit run... but if you add this class to the game project, it wont build the class until after it needs it and you will get an error.

So you actaully have to add an additional project to your solution to hold this class and make your game project and content project dependent on it so it is the first project to build. Then by the time the game project runs, it is aware of what a "MyGameInitialConfiguration" is and can load date into it.

Obviously, you can access that class instance from your game code and pull "path" from it.

Here is the end all for XNA knowledege: http://www.shawnhargreaves.com/blogindex.html

In particular, this blog: http://blogs.msdn.com/b/shawnhar/archive/2009/03/25/automatic-xnb-serialization-in-xna-game-studio-3-1.aspx

thank you for this question, took me back so many years. the Xna content pipeline was awesome.