Exemple #1
0
            // Many TmxObjectTypes are distinguished by null values in fields
            // It might be smart to subclass TmxObject
            public TmxObject(XElement xObject)
            {
                Name = (string) xObject.Attribute("name") ?? "";
                Type = (string) xObject.Attribute("type");
                X = (int) xObject.Attribute("x");
                Y = (int) xObject.Attribute("y");
                Visible = (bool?) xObject.Attribute("visible") ?? true;
                Width = (int?) xObject.Attribute("width") ?? 0;
                Height = (int?) xObject.Attribute("height") ?? 0;
                Rotation = (double?) xObject.Attribute("rotation") ?? 0.0;

                // Assess object type and assign appropriate content
                XAttribute xGid = xObject.Attribute("gid");
                XElement xEllipse = xObject.Element("ellipse");
                XElement xPolygon = xObject.Element("polygon");
                XElement xPolyline = xObject.Element("polyline");

                if (xGid != null)
                {
                    Tile = new TmxLayerTile((uint) xGid, X, Y);
                    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 ObjectType = TmxObjectType.Basic;

                Properties = new PropertyDict(xObject.Element("properties"));
            }