Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }