示例#1
0
        public Sprite(Sprite copy)
        {
            this.Name        = copy.Name;
            this.Part        = copy.Part;
            this.PaletteName = copy.PaletteName;

            this.Height        = copy.Height;
            this.Width         = copy.Width;
            this.tickable      = copy.tickable;
            this.frames        = copy.frames;
            this.currentFrame  = 0;
            this.lastFrameTime = 0;
            this.HotSpot       = new Point(copy.HotSpot.X, copy.HotSpot.Y);
            this.BoundBox      = new RectangleF(0, 0, copy.Width, copy.Height);
            this.Playing       = false;
            this.Visible       = true;
            this.AnimDirection = copy.AnimDirection;
            this.AnimStyle     = copy.AnimStyle;
            this.Layer         = copy.Layer;

            this.Reversed = copy.Reversed;
            if (copy.SheetPath != null)
            {
                this.SheetPath = FilePath.FromRelative(copy.SheetPath.Relative, copy.SheetPath.BasePath);
            }
        }
示例#2
0
        public void AddIncludeFolders(IEnumerable <string> includePaths)
        {
            var folderPaths = includePaths.Select(p => FilePath.FromRelative(p, this.BaseDir));

            includeFolders.AddRange(folderPaths);

            includeFilesFromFolders.AddRange(folderPaths
                                             .SelectMany(f => Directory.EnumerateFiles(
                                                             f.Absolute, "*.xml", SearchOption.AllDirectories)
                                                         ).Select(p => FilePath.FromRelative(p, this.BaseDir)));
        }
示例#3
0
        public static Sprite FromXml(XElement element, string basePath)
        {
            XAttribute tileattr = element.RequireAttribute("tilesheet");
            Sprite     sprite;

            string sheetPath = Path.Combine(basePath, tileattr.Value);

            sprite           = FromXml(element);
            sprite.sheetPath = FilePath.FromRelative(tileattr.Value, basePath);
            return(sprite);
        }
示例#4
0
 public void AddIncludeFiles(IEnumerable <string> includePaths)
 {
     includeFiles.AddRange(includePaths.Select(p => FilePath.FromRelative(p, this.BaseDir)));
 }
示例#5
0
 public void AddIncludeFile(string includePath)
 {
     includeFiles.Add(FilePath.FromRelative(includePath, this.BaseDir));
 }
示例#6
0
        public static Tileset Load(FilePath path)
        {
            var tileset = new Tileset();

            tileset.FilePath = path;

            var doc    = XDocument.Load(path.Absolute);
            var reader = doc.Element("Tileset");

            if (reader == null)
            {
                throw new Exception("The specified tileset definition file does not contain a Tileset tag.");
            }

            var sheetPath = FilePath.FromRelative(reader.Attribute("tilesheet").Value, path.BasePath);

            tileset.ChangeSheetPath(sheetPath.Absolute);

            int size;

            if (!int.TryParse(reader.Attribute("tilesize").Value, out size))
            {
                throw new Exception("The tileset definition does not contain a valid tilesize attribute.");
            }
            tileset.TileSize = size;

            var propParent = reader.Element("TileProperties");

            if (propParent != null)
            {
                foreach (XElement propNode in propParent.Elements("Properties"))
                {
                    var prop = new TileProperties(propNode);
                    tileset.AddProperties(prop);
                }
            }

            foreach (XElement tileNode in reader.Elements("Tile"))
            {
                int    id   = int.Parse(tileNode.Attribute("id").Value);
                string name = tileNode.Attribute("name").Value;

                var spriteNode = tileNode.Element("Sprite");
                if (spriteNode == null)
                {
                    throw new GameXmlException(tileNode, "All Tile tags must contain a Sprite tag.");
                }

                var sprite     = Sprite.FromXml(spriteNode);
                var tileSprite = new TileSprite(tileset, sprite);

                Tile tile = new Tile(id, tileSprite);

                string     propName = "Default";
                XAttribute propAttr = tileNode.Attribute("properties");
                if (propAttr != null)
                {
                    propName = propAttr.Value;
                }

                tile.Properties = tileset.GetProperties(propName);

                tile.Sprite.Play();
                tileset.Add(tile);
            }

            return(tileset);
        }