当前位置: 首页>>代码示例>>C++>>正文


C++ TileLayer::setNumColumns方法代码示例

本文整理汇总了C++中TileLayer::setNumColumns方法的典型用法代码示例。如果您正苦于以下问题:C++ TileLayer::setNumColumns方法的具体用法?C++ TileLayer::setNumColumns怎么用?C++ TileLayer::setNumColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileLayer的用法示例。


在下文中一共展示了TileLayer::setNumColumns方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: collidable


//.........这里部分代码省略.........
    
    
    //Find data node then store it
    //pDataNode = findElement("data", pTileElement->FirstChildElement());
    bool isBase64  = false ;
    bool isZlibCompressed = false;
    
    TiXmlElement* pDataNode= 0;
    
    for (TiXmlElement* e = pTileElement->FirstChildElement();
         e != NULL; e = e->NextSiblingElement()){
        if (e->Value() == string("data")){
            pDataNode = e;
            
            //Check if encoded/compressed
            if (e->Attribute("encoding")){
                if (e->Attribute("encoding") == string("base64")){
                    isBase64 = true;
                }
            }
            
            if (e->Attribute("compression")){
                if (e->Attribute("compression") == string("zlib")){
                    isZlibCompressed = true;
                }
            }
        }
    }
    
    
    //Decode data and store
    string decodedIDs;
    
    if (pDataNode && isBase64){
        for (TiXmlNode* e = pDataNode->FirstChild(); e != NULL; e = e->NextSibling()){
            TiXmlText* text = e ->ToText();
            string t = text->Value();
            decodedIDs = base64_decode(t);
        }
    }
    
    //Placeholder for data
    vector<vector<int>> data;
    
    //Calculate number of GIDS present
    uLongf numGids = m_width * m_height * sizeof(int);
    vector<unsigned> gids(numGids);
    
    
    //Horizontal register for vector
    vector<int> layerRow(m_width);
    
    //Build empty data vector to fill
    for(int j = 0 ; j < m_height; j++){
        data.push_back(layerRow);
    }
    
    //Compressed data assignment
    if (isZlibCompressed){
        uncompress
        ((Bytef*)&gids[0], &numGids, (const Bytef*)decodedIDs.c_str(), decodedIDs.size());
        
        
        for (int rows = 0 ; rows <m_height; rows++){
            for (int cols = 0; cols < m_width; cols++){
                data[rows][cols] = gids[rows * m_width + cols];
            }
        }
    } else {
        //Uncompressed data assignment
        int index = 0;
        int tileID = 0;
        
        //Find all tiles, assign GID to proper data vector place
        for (TiXmlElement* e = pDataNode->FirstChildElement();
             e != NULL; e = e->NextSiblingElement()){
            
            e->Attribute("gid",&tileID);
            data[index / m_width][index % m_width] = tileID;
            index++;
        }
    }
    
    
    //Set Tile Layer properties
    pTileLayer->setTileIDs(data);
    pTileLayer->setNumColumns(m_width);
    pTileLayer->setNumRows(m_height);
    
    //Save new tile layer to Level
    cout << "Added new layer\n";
    pLayers->push_back(pTileLayer);
    
    //Add collision tiles to collision layer
    if (collidable){
        pCollisionLayers->push_back(pTileLayer);
        cout << "Added new collision layer\n";
    }
    
}
开发者ID:iiechapman,项目名称:Sandman2D,代码行数:101,代码来源:LevelParser.cpp


注:本文中的TileLayer::setNumColumns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。