/// <summary> /// initializes a TMX Tiled Map with a TMX file /// </summary> public bool initWithTMXFile(string tmxFile) { Debug.Assert(tmxFile != null && tmxFile.Length > 0, "TMXTiledMap: tmx file should not bi nil"); contentSize = new CCSize(0, 0); CCTMXMapInfo mapInfo = CCTMXMapInfo.formatWithTMXFile(tmxFile); if (mapInfo == null) { return(false); } Debug.Assert(mapInfo.Tilesets.Count != 0, "TMXTiledMap: Map not found. Please check the filename."); m_tMapSize = mapInfo.MapSize; m_tTileSize = mapInfo.TileSize; m_nMapOrientation = mapInfo.Orientation; ObjectGroups = mapInfo.ObjectGroups; Properties = mapInfo.Properties; m_pTileProperties = mapInfo.TileProperties; int idx = 0; //Layers List <CCTMXLayerInfo> layers = mapInfo.Layers; if (layers != null && layers.Count > 0) { if (null == m_pTMXLayers) { m_pTMXLayers = new Dictionary <string, CCTMXLayer>(); Debug.Assert(m_pTMXLayers != null, "Allocate memory failed!"); } for (int i = 0; i < layers.Count; i++) { CCTMXLayerInfo layerInfo = layers[i]; if (layerInfo != null && layerInfo.m_bVisible) { CCTMXLayer child = parseLayer(layerInfo, mapInfo); addChild(child, idx, idx); // record the CCTMXLayer object by it's name string layerName = child.LayerName; m_pTMXLayers.Add(layerName, child); // update content size with the max size CCSize childSize = child.contentSize; CCSize currentSize = this.contentSize; currentSize.width = Math.Max(currentSize.width, childSize.width); currentSize.height = Math.Max(currentSize.height, childSize.height); this.contentSize = currentSize; idx++; } } } return(true); }
private CCTMXLayer parseLayer(CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { CCTMXTilesetInfo cCTMXTilesetInfo = this.tilesetForLayer(layerInfo, mapInfo); CCTMXLayer cCTMXLayer = CCTMXLayer.layerWithTilesetInfo(cCTMXTilesetInfo, layerInfo, mapInfo); layerInfo.m_bOwnTiles = false; cCTMXLayer.setupTiles(); return(cCTMXLayer); }
/// <summary> /// creates a CCTMXLayer with an tileset info, a layer info and a map info /// </summary> public static CCTMXLayer layerWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { CCTMXLayer pRet = new CCTMXLayer(); if (pRet.initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo)) { return(pRet); } return(null); }
private CCTMXLayer parseLayer(CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { CCTMXTilesetInfo tileset = tilesetForLayer(layerInfo, mapInfo); CCTMXLayer layer = CCTMXLayer.layerWithTilesetInfo(tileset, layerInfo, mapInfo); // tell the layerinfo to release the ownership of the tiles map. layerInfo.m_bOwnTiles = false; layer.setupTiles(); return(layer); }
public bool initWithTMXFile(string tmxFile) { this.contentSize = new CCSize(0f, 0f); CCTMXMapInfo cCTMXMapInfo = CCTMXMapInfo.formatWithTMXFile(tmxFile); if (cCTMXMapInfo == null) { return(false); } this.m_tMapSize = cCTMXMapInfo.MapSize; this.m_tTileSize = cCTMXMapInfo.TileSize; this.m_nMapOrientation = cCTMXMapInfo.Orientation; this.ObjectGroups = cCTMXMapInfo.ObjectGroups; this.Properties = cCTMXMapInfo.Properties; this.m_pTileProperties = cCTMXMapInfo.TileProperties; int num = 0; List <CCTMXLayerInfo> layers = cCTMXMapInfo.Layers; if (layers != null && layers.Count > 0) { if (this.m_pTMXLayers == null) { this.m_pTMXLayers = new Dictionary <string, CCTMXLayer>(); } for (int i = 0; i < layers.Count; i++) { CCTMXLayerInfo item = layers[i]; if (item != null && item.m_bVisible) { CCTMXLayer cCTMXLayer = this.parseLayer(item, cCTMXMapInfo); this.addChild(cCTMXLayer, num, num); string layerName = cCTMXLayer.LayerName; this.m_pTMXLayers.Add(layerName, cCTMXLayer); CCSize cCSize = cCTMXLayer.contentSize; CCSize cCSize1 = this.contentSize; cCSize1.width = Math.Max(cCSize1.width, cCSize.width); cCSize1.height = Math.Max(cCSize1.height, cCSize.height); this.contentSize = cCSize1; num++; } } } return(true); }
/// <summary> /// creates a CCTMXLayer with an tileset info, a layer info and a map info /// </summary> public static CCTMXLayer layerWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { CCTMXLayer pRet = new CCTMXLayer(); if (pRet.initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo)) { return pRet; } return null; }
/** creates a CCTMXLayer with an tileset info, a layer info and a map info */ public static CCTMXLayer Create(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { var pRet = new CCTMXLayer(); pRet.InitWithTilesetInfo(tilesetInfo, layerInfo, mapInfo); return pRet; }
private CCTMXLayer ParseLayer(CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo) { CCTMXTilesetInfo tileset = tilesetForLayer(layerInfo, mapInfo); CCTMXLayer layer = new CCTMXLayer(tileset, layerInfo, mapInfo); // tell the layerinfo to release the ownership of the tiles map. layerInfo.OwnTiles = false; layer.SetupTiles(); return layer; }