Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Having trouble building XML in content pipeline tool

$
0
0

@BHZ_Mayor wrote:

I'm having trouble getting my XML in the right format to build in the content pipeline tool. I used TexturePacker (free version) to generate xml for my spritesheet. It looks like this.

<TextureAtlas imagePath="testsheet.png" width="497" height="98">
    <sprite n="stand/sample_stand_small.png" x="1" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small1.png" x="56" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small2.png" x="111" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small3.png" x="166" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small4.png" x="221" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small5.png" x="276" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small6.png" x="331" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small7.png" x="386" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small8.png" x="441" y="1" w="55" h="96"/>
</TextureAtlas>

I've created separate data project with a class which looks like below. I have also set up the proper references between my main project and data project.

namespace SheetData
{
    [XmlRoot("TextureAtlas")]
    public class TextureAtlas
    {
        [XmlAttribute("imagePath")]
        public string imagePath;

        [XmlAttribute]
        public int width;

        [XmlAttribute]
        public int height;

        [XmlElement("sprite")]
        public List<SheetSprite> sheetSprites;
    }

    public class SheetSprite
    {
        [XmlAttribute]
        public string n;

        [XmlAttribute]
        public int x;

        [XmlAttribute]
        public int y;

        [XmlAttribute]
        public int w;

        [XmlAttribute]
        public int h;
    }
}

I then tried to convert my XML to the required format for Monogame as follows.

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:ns="Microsoft.Xna.Framework">
  <Asset Type="SheetData.TextureAtlas" imagePath="testsheet.png" width="497" height="98">
    <sprite n="stand/sample_stand_small.png" x="1" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small1.png" x="56" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small2.png" x="111" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small3.png" x="166" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small4.png" x="221" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small5.png" x="276" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small6.png" x="331" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small7.png" x="386" y="1" w="55" h="96"/>
    <sprite n="walk/walk_small8.png" x="441" y="1" w="55" h="96"/>
  </Asset>
</XnaContent>

But when I try to build in the content pipeline tool. I get the error, "The Xml element 'imagePath' is required, but element 'sprite' was found at 4:6. Try changing the element order or add missing elements."

As shown in the original XML and the data class, "imagePath" is supposed to be an attribute of TextureAtlas, not an element. How can I get it to read the elements and attributes properly?

Thanks in advance.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles