Sunday, June 24, 2018

c# - How do I load Gleed 2D levels in WP7 XNA game?


I've been trying so long to use this modified version of GLEED2D that includes WP7 support,


I'm stuck into loading the level into my game, now my Game1.cs class has the following:


    protected override void Initialize()
{

Stream stream = TitleContainer.OpenStream("Content/leveltest.xml");
XElement xml = XElement.Load(stream);
level = LevelLoader.Load(xml);
base.Initialize();

}

I included the XML file of my level into Content Directory, when I try to build the solution, It gives this error:


XML is not in the XNA intermediate format. Missing XnaContent root element.

I didn't find any reference on how to fix it on the developer's blog or the github WiKi


Any Idea?



Answer



The problem is that you're trying to build the XML file using the XNA's Content Pipeline. However, in the source code you posted, the XML file is being loaded at runtime using the LINQ to XML API (XDocument) so it doesn't need to go through the content pipeline.


To solve the problem, go to the Solution Explorer, browse into your Content project to your XML file, and then on its Properties, change the Build Action property from Compile to Content, and also enable the Copy to Output Directory property. See picture below:



enter image description here


This way your XML file will still be copied to the Content folder, without being built by the XNA's Content Pipeline.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...