public CCTMXTiledLayer getTiledLayer(string name) { for (int i = 0; i < layers.Length; i++) { CCTMXLayer layer = layers[i]; if (layer.name == name && layer is CCTMXTiledLayer) { return(layer as CCTMXTiledLayer); } } return(null); }
public CCTMXObjectGroup getObjectGroup(string name) { for (int i = 0; i < layers.Length; i++) { CCTMXLayer layer = layers[i]; if (layer.name == name && layer is CCTMXObjectGroup) { return(layer as CCTMXObjectGroup); } } return(null); }
public static CCTMXMap Parse(string file, NSDictionary tilesetCaches = null) { string text = LoadText(file); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(text); XmlNodeList nodeList = xmlDoc.DocumentElement.ChildNodes; // get mapWidth, mapHeight, tileWidth, tileHeight XmlNode mapNode = xmlDoc.DocumentElement; float version = float.Parse(mapNode.Attributes["version"].InnerText); if (!FloatUtils.EQ(version, 1.0f)) { CCDebug.Warning("cocos2d:CCTMXMap: Found {0} tmx file, but only 1.0 version was tested.", version); } string dir = file.Replace(Path.GetFileName(file), ""); CCTMXMap map = new CCTMXMap(); map.fileName = file; map.cols = int.Parse(mapNode.Attributes["width"].InnerText); map.rows = int.Parse(mapNode.Attributes["height"].InnerText); map.tileWidth = int.Parse(mapNode.Attributes["tilewidth"].InnerText); map.tileHeight = int.Parse(mapNode.Attributes["tileheight"].InnerText); Dictionary <int, string> gidToFiles = new Dictionary <int, string> (256); Dictionary <int, Dictionary <string, string> > gidToTileProperties = new Dictionary <int, Dictionary <string, string> > (256); List <CCTMXLayer> layers = new List <CCTMXLayer> (8); var enumerator = nodeList.GetEnumerator(); while (enumerator.MoveNext()) { XmlNode nodeData = (XmlNode)enumerator.Current; if (nodeData.Name == "tileset") { ParseTileset(nodeData, gidToFiles, gidToTileProperties, dir, tilesetCaches); } else if (nodeData.Name == "layer") { CCTMXLayer layer = ParseLayer(nodeData, map.cols, map.rows, gidToFiles, gidToTileProperties); layers.Add(layer); } else if (nodeData.Name == "objectgroup") { CCTMXLayer layer = ParseObjectGroup(nodeData, map.cols, map.rows, map.tileWidth, map.tileHeight, gidToFiles, gidToTileProperties); layers.Add(layer); } else if (nodeData.Name == "properties") { if (map.properties == null) { map.properties = new Dictionary <string, string>(); } ParseProperties(nodeData, map.properties); } } map.gidToFiles = gidToFiles; map.gidToTileProperties = gidToTileProperties; map.layers = layers.ToArray(); return(map); }