public TmxObject(XElement xObject, Dictionary <string, TmxTypeDefaults> defaults = null) { Id = (int?)xObject.Attribute("id") ?? 0; Name = (string)xObject.Attribute("name") ?? String.Empty; X = (double)xObject.Attribute("x"); Y = (double)xObject.Attribute("y"); Width = (double?)xObject.Attribute("width") ?? 0.0; Height = (double?)xObject.Attribute("height") ?? 0.0; Type = (string)xObject.Attribute("type") ?? String.Empty; Visible = (bool?)xObject.Attribute("visible") ?? true; Rotation = (double?)xObject.Attribute("rotation") ?? 0.0; // 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"); if (xGid != null) { Tile = new TmxLayerTile((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 { ObjectType = TmxObjectType.Basic; } var xText = xObject.Element("text"); if (xText != null) { Text = new TmxText(xText); } TmxTypeDefaults typeDefaults = null; defaults.TryGetValue(Type, out typeDefaults); Properties = new PropertyDict(xObject.Element("properties"), typeDefaults); }
/// <summary> /// Initializes a new instance of the <see cref="LayerTile" /> class. /// </summary>> /// <param name="tmxTile">The TMX parsed tile.</param> /// <param name="tileset">Th</param> public LayerTile(TmxLayerTile tmxTile, Tileset tileset) { this.X = tmxTile.X; this.Y = tmxTile.Y; this.HorizontalFlip = tmxTile.HorizontalFlip; this.VerticalFlip = tmxTile.VerticalFlip; this.DiagonalFlip = tmxTile.DiagonalFlip; if (tileset != null) { this.Tileset = tileset; this.Id = tmxTile.Gid - this.Tileset.FirstGid; this.TilesetTile = this.Tileset.TilesTable[this.Id]; } }
public TmxObject(XElement xObject) { Name = (string)xObject.Attribute("name") ?? string.Empty; X = (double)xObject.Attribute("x"); Y = (double)xObject.Attribute("y"); Width = (double?)xObject.Attribute("width") ?? 0.0; Height = (double?)xObject.Attribute("height") ?? 0.0; Type = (string)xObject.Attribute("type") ?? string.Empty; Visible = (bool?)xObject.Attribute("visible") ?? true; Rotation = (double?)xObject.Attribute("rotation") ?? 0.0; // 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"); if (xGid != null) { Tile = new TmxLayerTile((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 { ObjectType = TmxObjectType.Basic; } Properties = new PropertyDict(xObject.Element("properties")); }
public TmxObject(XElement xObject) { Id = (int?)xObject.Attribute("id") ?? 0; Name = (string)xObject.Attribute("name") ?? String.Empty; X = (double)xObject.Attribute("x"); Y = (double)xObject.Attribute("y"); Width = (double?)xObject.Attribute("width") ?? 0.0; Height = (double?)xObject.Attribute("height") ?? 0.0; Type = (string)xObject.Attribute("type") ?? String.Empty; Visible = (bool?)xObject.Attribute("visible") ?? true; Rotation = (double?)xObject.Attribute("rotation") ?? 0.0; // 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"); if (xGid != null) { Tile = new TmxLayerTile((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 ObjectType = TmxObjectType.Basic; Properties = new PropertyDict(xObject.Element("properties")); }
private static Tile LoadTile(TmxLayer tmxLayer, TmxLayerTile tmxTile, Tileset[] tilesets, ContentManager content, GraphicsDevice graphicsDevice) { Tile tile = null; if (tmxTile.Gid != 0) { // Try and find the tileset. foreach (var tileset in tilesets) { if (tmxTile.Gid >= tileset.FirstGid && tmxTile.Gid <= tileset.LastGid) { int srcY = (((tmxTile.Gid - tileset.FirstGid) / tileset.TilesPerRow) * 32); int srcX = (((tmxTile.Gid - tileset.FirstGid) % tileset.TilesPerRow) * 32); tile = new Tile(tileset, new Rectangle(srcX, srcY, tileset.TileWidth, tileset.TileHeight), new Vector2(tmxTile.X * 32, tmxTile.Y * 32), tmxLayer.Opacity); break; } } } return tile ?? new Tile(null, new Rectangle(), Vector2.Zero, tmxLayer.Opacity); }
/// <summary> /// This method creates object viewer by object view index, isVisible parameter and object type. /// It takes image from dictionary, loaded previously, by id. /// </summary> /// <param name="objType"></param> /// <param name="id"></param> /// <param name="isVisible"></param> /// <returns></returns> private Viewer GetObjectView(TmxLayerTile tile, Boolean isVisible) { Viewer viewer = null; if (tile != null) { viewer = CreateViewer(tile.Gid, isVisible); viewer.Enabled = isVisible; } return viewer; }