Esempio n. 1
0
        /// <summary>
        /// Parses an xml sprite
        /// </summary>
        /// <param name="spriteElement">The sprite element to parse.</param>
        /// <returns></returns>
        private SpriteComponent ParseSpriteComponent(XElement spriteElement)
        {
            EntityIoLogger.WriteIoInformation(spriteElement, IoType.Component, _currentComponent.LineNumber());

            var sprite = new SpriteComponent()
            {
                Height       = ParseFloat(spriteElement.Element("height"), "height"),
                Width        = ParseFloat(spriteElement.Element("width"), "width"),
                SourceRect   = ParseNullableRectangle(spriteElement.Element("texturerect"), "texturerect"),
                Color        = ParseColor(spriteElement.Element("color"), "color"),
                Rotatation   = ParseFloat(spriteElement.Element("rotation"), "rotation"),
                Scale        = ParseVector2(spriteElement.Element("scale"), "scale", Vector2.One),
                SpriteEffect = ParseSpriteEffects(spriteElement.Element("spriteeffects")),
                DepthLayer   = ParseFloat(spriteElement.Element("depth"), "depth"),
                Texture      = _renderableController.GetTextureByFilename(spriteElement.Element("texture").Value),
            };

            /* If the origin is set in the XML file, use that. Otherwise,
             * default to the middle of the sprite. */
            sprite.Origin = spriteElement.Element("origin") == null
                                ? new Vector2(sprite.Texture.Width / 2, sprite.Texture.Height / 2)
                                : ParseVector2(spriteElement.Element("origin"), "origin");

            return(sprite);
        }