Esempio n. 1
0
        /** initializes a CCTMXLayer with a tileset info, a layer info and a map info */

        public bool InitWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo)
        {
            // XXX: is 35% a good estimate ?
            CCSize size = layerInfo.LayerSize;
            float  totalNumberOfTiles = size.Width * size.Height;
            float  capacity           = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ?

            CCTexture2D texture = null;

            if (tilesetInfo != null)
            {
                texture = CCTextureCache.SharedTextureCache.AddImage(tilesetInfo.m_sSourceImage);
            }

            if (base.InitWithTexture(texture, (int)capacity))
            {
                // layerInfo
                m_sLayerName          = layerInfo.Name;
                m_tLayerSize          = size;
                m_pTiles              = layerInfo.Tiles;
                m_uMinGID             = layerInfo.MinGID;
                m_uMaxGID             = layerInfo.MaxGID;
                m_cOpacity            = layerInfo.Opacity;
                Properties            = new Dictionary <string, string>(layerInfo.Properties);
                m_fContentScaleFactor = CCDirector.SharedDirector.ContentScaleFactor;

                // tilesetInfo
                m_pTileSet = tilesetInfo;

                // mapInfo
                m_tMapTileSize      = mapInfo.TileSize;
                m_uLayerOrientation = (CCTMXOrientation)mapInfo.Orientation;

                // offset (after layer orientation is set);
                CCPoint offset = CalculateLayerOffset(layerInfo.Offset);
                Position = offset.PixelsToPoints();

                m_pAtlasIndexArray = new List <int>((int)totalNumberOfTiles);

                var contentSize = new CCSize(m_tLayerSize.Width * m_tMapTileSize.Width,
                                             m_tLayerSize.Height * m_tMapTileSize.Height);

                ContentSize = contentSize.PixelsToPoints();

                m_bUseAutomaticVertexZ = false;
                m_nVertexZvalue        = 0;

                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        /** initializes a CCTMXLayer with a tileset info, a layer info and a map info */

        public bool InitWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo)
        {
            // XXX: is 35% a good estimate ?
            CCSize size = layerInfo.LayerSize;
            float totalNumberOfTiles = size.Width * size.Height;
            float capacity = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ?

            CCTexture2D texture = null;
            if (tilesetInfo != null)
            {
                texture = CCTextureCache.SharedTextureCache.AddImage(tilesetInfo.m_sSourceImage);
            }

            if (base.InitWithTexture(texture, (int) capacity))
            {
                // layerInfo
                m_sLayerName = layerInfo.Name;
                m_tLayerSize = size;
                m_pTiles = layerInfo.Tiles;
                m_uMinGID = layerInfo.MinGID;
                m_uMaxGID = layerInfo.MaxGID;
                m_cOpacity = layerInfo.Opacity;
                Properties = new Dictionary<string, string>(layerInfo.Properties);
                m_fContentScaleFactor = CCDirector.SharedDirector.ContentScaleFactor;

                // tilesetInfo
                m_pTileSet = tilesetInfo;

                // mapInfo
                m_tMapTileSize = mapInfo.TileSize;
                m_uLayerOrientation = (CCTMXOrientation) mapInfo.Orientation;

                // offset (after layer orientation is set);
                CCPoint offset = CalculateLayerOffset(layerInfo.Offset);
                Position = CCMacros.CCPointPixelsToPoints(offset);

                m_pAtlasIndexArray = new List<int>((int) totalNumberOfTiles);

                ContentSize =
                    CCMacros.CCSizePixelsToPoints(new CCSize(m_tLayerSize.Width * m_tMapTileSize.Width,
                                                                 m_tLayerSize.Height * m_tMapTileSize.Height));

                m_bUseAutomaticVertexZ = false;
                m_nVertexZvalue = 0;

                return true;
            }
            return false;
        }