@xnamahx wrote:
Hi monos!
Im pretty new on monogame, c# and all this enviroment.
To start simple im trying to load a sprites sheet and add actions. From the content pipeline im only being able to add the png file but cant do it with the xml file (created with ShoeBox), it looks like this:<TextureAtlas imagePath="sprite.png"> <SubTexture name="sprite_01.png" x="568" y="959" width="66" height="75"/> <SubTexture name="sprite_02.png" x="636" y="981" width="66" height="76"/> <SubTexture name="sprite_03.png" x="498" y="1416" width="68" height="78"/> <SubTexture name="sprite_04.png" x="497" y="1264" width="69" height="79"/> </TextureAtlas>
So I went doing it manually as follows:
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); var myTexture = Content.Load<Texture2D>("Sprites/sprite"); var myAtlas = new TextureAtlas("myMap", myTexture ); XmlDocument xdoc = new XmlDocument(); xdoc.Load("Content/Sprites/myMap.xml"); var texturesAtlas = xdoc.SelectNodes("TextureAtlas"); foreach (XmlNode textureAtlas in texturesAtlas) { foreach (XmlNode frame in textureAtlas.SelectNodes("SubTexture")) { var name = frame.Attributes.GetNamedItem("name").Value; var width = Int32.Parse(frame.Attributes.GetNamedItem("width").Value); var height = Int32.Parse(frame.Attributes.GetNamedItem("height").Value); var x = Int32.Parse(frame.Attributes.GetNamedItem("x").Value); var y = Int32.Parse(frame.Attributes.GetNamedItem("y").Value); myAtlas.CreateRegion(name,x,y,width,height); } } var myAnimationFactory = new SpriteSheetAnimationFactory(myAtlas ); myAnimationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0,1,2,1 })); myCharacter = new AnimatedSprite(myAnimationFactory); myCharacter.Position = new Vector2(350, 800); myCharacter.Play("idle").IsLooping = true; }
it works but im wondering if there is a better way to import the map, or to choose a xml file while creating the TextureAtlas with TextureAtlas.Create("name", texture, w, h);
Maybe doing a custom content importer? its seems complicated
Thanks
Posts: 4
Participants: 3