Exemplo n.º 1
0
        public TmxObject(TmxMap map, XElement xObject)
        {
            Id       = (int?)xObject.Attribute("id") ?? 0;
            Name     = (string)xObject.Attribute("name") ?? string.Empty;
            X        = (float)xObject.Attribute("x");
            Y        = (float)xObject.Attribute("y");
            Width    = (float?)xObject.Attribute("width") ?? 0.0f;
            Height   = (float?)xObject.Attribute("height") ?? 0.0f;
            Type     = (string)xObject.Attribute("type") ?? string.Empty;
            Visible  = (bool?)xObject.Attribute("visible") ?? true;
            Rotation = (float?)xObject.Attribute("rotation") ?? 0.0f;

            // Assess object type and assign appropriate content
            var xGid      = xObject.Attribute("gid");
            var xEllipse  = xObject.Element("ellipse");
            var xPolygon  = xObject.Element("polygon");
            var xPolyline = xObject.Element("polyline");
            var xText     = xObject.Element("text");
            var xPoint    = xObject.Element("point");

            if (xGid != null)
            {
                Tile       = new TmxLayerTile(map, (uint)xGid, Convert.ToInt32(Math.Round(X)), Convert.ToInt32(Math.Round(X)));
                ObjectType = TmxObjectType.Tile;
            }
            else if (xEllipse != null)
            {
                ObjectType = TmxObjectType.Ellipse;
            }
            else if (xPolygon != null)
            {
                Points     = ParsePoints(xPolygon);
                ObjectType = TmxObjectType.Polygon;
            }
            else if (xPolyline != null)
            {
                Points     = ParsePoints(xPolyline);
                ObjectType = TmxObjectType.Polyline;
            }
            else if (xText != null)
            {
                Text       = new TmxText(xText);
                ObjectType = TmxObjectType.Text;
            }
            else if (xPoint != null)
            {
                ObjectType = TmxObjectType.Point;
            }
            else
            {
                ObjectType = TmxObjectType.Basic;
            }

            Properties = PropertyDict.ParsePropertyDict(xObject.Element("properties"));
        }
Exemplo n.º 2
0
        public static TmxText LoadTmxText(this TmxText text, XElement xText)
        {
            text.FontFamily = (string)xText.Attribute("fontfamily") ?? "sans-serif";
            text.PixelSize  = (int?)xText.Attribute("pixelsize") ?? 16;
            text.Wrap       = (bool?)xText.Attribute("wrap") ?? false;
            text.Color      = ParseColor(xText.Attribute("color"));
            text.Bold       = (bool?)xText.Attribute("bold") ?? false;
            text.Italic     = (bool?)xText.Attribute("italic") ?? false;
            text.Underline  = (bool?)xText.Attribute("underline") ?? false;
            text.Strikeout  = (bool?)xText.Attribute("strikeout") ?? false;
            text.Kerning    = (bool?)xText.Attribute("kerning") ?? true;
            text.Alignment  = new TmxAlignment().LoadTmxAlignment(xText);
            text.Value      = xText.Value;

            return(text);
        }