示例#1
0
        public void ReadXml(string xmlPath)
        {
            //this will read the xml
            SpriteXml currentItem;

            //https://support.microsoft.com/en-au/help/307548/how-to-read-xml-from-a-file-by-using-visual-c
            using (XmlTextReader reader = new XmlTextReader(xmlPath))
            {
                while (reader.Read())
                {
                    currentItem = new SpriteXml();
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:                // The node is an element.
                        while (reader.MoveToNextAttribute()) // Read the attributes.
                                                             // this will place all correct values into list object to refrenc when extracting sprite from sheet
                        {
                            switch (reader.Name)
                            {
                            case "name":
                                currentItem.Name = reader.Value;
                                break;

                            case "x":
                                currentItem.PosX = int.Parse(reader.Value);
                                break;

                            case "y":
                                currentItem.PosY = int.Parse(reader.Value);
                                break;

                            case "width":
                                currentItem.Width = int.Parse(reader.Value);
                                break;

                            case "height":
                                currentItem.Height = int.Parse(reader.Value);
                                break;
                            }
                        }
                        spriteList.Add(currentItem);
                        break;
                    }
                }
            }
        }
示例#2
0
        public float  GetSpritHeight(string spriteName)
        {
            SpriteXml sprite = spriteList.Find(x => x.Name == spriteName);

            return((float)sprite.Height);
        }
示例#3
0
        public void Draw(SpriteBatch spriteBatch, Vector2 pos, Vector2 imgScale, string spriteName, Color?color = null)
        {
            SpriteXml sprite = spriteList.Find(x => x.Name == spriteName);

            spriteBatch.Draw(texture: GetSpriteSheet(), position: pos, sourceRectangle: sprite.GetRect(), scale: imgScale);
        }
示例#4
0
        public float GetSpritWidth(string spriteName)
        {
            SpriteXml sprite = spriteList.Find(x => x.Name == spriteName);

            return((float)sprite.Width);
        }