Esempio n. 1
0
        public Animation(Game g, string file, string animationName)
        {
            var x  = Xml.Open(Xml.FromFile(file), "animations");
            var sx = x.ElementsNamed("animation", animationName).FirstOrNull();

            if (sx == null)
            {
                throw new Exception(file + " does not contain " + animationName);
            }

            timePerFrame = sx.GetAttributeFloat("time");

            int    size  = sx.GetAttributeInt("size");
            string img   = sx.GetAttributeString("img");
            int    start = sx.GetAttributeInt("start");
            int    end   = sx.GetAttributeInt("end");

            if (end < start)
            {
                throw new Exception("end < start");
            }

            for (int spriteIndex = start; spriteIndex <= end; ++spriteIndex)
            {
                sprites.Add(Tiles.CreateSprite(g.fetchImage(img), spriteIndex, size, size));
            }

            reset();
        }
Esempio n. 2
0
        internal Layer(World world, System.Xml.XmlElement la, int tilewidth, int tileheight, SFML.Graphics.Image image)
        {
            Name            = la.GetAttributeString("name");
            width           = la.GetAttributeInt("width");
            height          = la.GetAttributeInt("height");
            this.tilewidth  = tilewidth;
            this.tileheight = tileheight;

            tiles = new int[width * height];

            var data  = la.FirstElement("data");
            int index = 0;

            foreach (var tile in data.ElementsNamed("tile"))
            {
                var gid = tile.GetAttributeInt("gid");
                tiles[index] = gid;
                ++index;
            }

            foreach (var o in ObjectDatas)
            {
                if (o.gid != 0)
                {
                    var sp = Tiles.CreateSprite(image, o.gid, tilewidth, tileheight);
                    sp.Position = o.pos;
                    sprites.Add(sp);
                }
            }
        }