示例#1
0
        /// <summary>
        /// Builds the XML document of the atlas
        /// </summary>
        public void BuildXML(string imagePath = null)
        {
            // def
            if (imagePath == null)
            {
                imagePath = "null";
            }

            // Populate with subsprites
            Object[] XMLelem = new Object[SubspriteList.Count];
            for (int i = 0; i < SubspriteList.Count; i++)
            {
                // Create the subsprite
                XElement node = new XElement("SubTexture");

                // Cache this shit so I don't have to type it every time
                Subsprite curSub = SubspriteList[i];

                // Add the attributes of the subsprite
                node.SetAttributeValue("name", curSub.Name);
                node.SetAttributeValue("x", curSub.Pos.X);
                node.SetAttributeValue("y", curSub.Pos.Y);
                node.SetAttributeValue("width", curSub.Dims.Width);
                node.SetAttributeValue("height", curSub.Dims.Height);

                // Stuff shit into array
                XMLelem[i] = node;
            }

            XElement XMLRootNode = new XElement("TextureAtlas", XMLelem); // nest the subsprites

            XMLRootNode.SetAttributeValue("imagePath", imagePath);        // this will come after

            // Create Declaration - this will be hard coded for now
            XDeclaration XMLdec = new XDeclaration("1.0", "utf-8", "yes");

            // Create Doc
            XDocument XMLdoc = new XDocument(XMLdec, XMLRootNode);

            // Record doc
            AtlasXML = XMLdoc;
        }
示例#2
0
        private void stripSorter(List <Subsprite> subsprites)
        {
            // Value to offset by
            int xOffset = 0;
            int yOffset = 0;

            int bigHeight = 0;

            for (int i = 0; i < SubspriteList.Count; i++)
            {
                // Store current subsprite
                Subsprite curSub = SubspriteList[i];

                // Wrap when necessary
                if (xOffset + curSub.Dims.Width > targetDims.X)
                {
                    xOffset  = 0;
                    yOffset += bigHeight;

                    // reset bigHeight
                    bigHeight = 0;
                }

                // Write position to Subsprite
                SubspriteList[i].Pos = new Vector(xOffset, yOffset);

                // Cumulative offset
                xOffset += SubspriteList[i].bitmapData.PixelWidth + Offset;

                if ((int)SubspriteList[i].Dims.Height + Offset > bigHeight)
                {
                    bigHeight = (int)curSub.Dims.Height + Offset;
                }

                Debug.Assert(yOffset < targetDims.Y);
            }
        }
示例#3
0
 /// <summary>
 /// Removes a subsprite from the list
 /// </summary>
 /// <param name="removeSub">Subsprite to be removed from the list</param>
 public void RemoveSubsprite(Subsprite removeSub)
 {
     SubspriteList.Remove(removeSub);
 }
示例#4
0
 /// <summary>
 /// Adds a subsprite into the list
 /// </summary>
 /// <param name="addSub">Subsprite to be added to the list</param>
 public void AddSubsprite(Subsprite addSub)
 {
     SubspriteList.Add(addSub);
 }