示例#1
0
        /* #################################################################### */
        /* #                              METHODS                             # */
        /* #################################################################### */

        public void Load(string filepath)
        {
            Log.Instance.Debug($"Loading Spritesheet {filepath}.");

            // First get the data about the sprites
            var filestream = new StreamReader(filepath);
            var serializer = new XmlSerializer(typeof(XmlTextureAtlas));
            var atlas      = (XmlTextureAtlas)serializer.Deserialize(filestream);

            // Full filename information
            var imagefile = Path.Combine(Path.GetDirectoryName(filepath), atlas.imagePath);

            // Now load the image itself
            _texture = new SDLTexture();
            _texture.Load(imagefile);

            // Set up the basic SpriteSheet data.
            Name = Path.GetFileNameWithoutExtension(atlas.imagePath);

            // Add each sprite-set to the sheet.
            foreach (var data in atlas.Sprites)
            {
                var sprite = new Sprite(_texture)
                {
                    Name   = data.name,
                    X      = data.x,
                    Y      = data.y,
                    Width  = data.width,
                    Height = data.height,
                    Px     = data.pivotX,
                    Py     = data.pivotY
                };

                Sprites.Add(sprite.Name, sprite);
            }
        }
示例#2
0
 /* #################################################################### */
 /* #                           CONSTRUCTORS                           # */
 /* #################################################################### */
 public Sprite(SDLTexture texture)
 {
     Texture  = texture;
     Centered = false;
 }