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


C++ Map::getWidth方法代码示例

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


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

示例1: rec

    Map(std::vector<bool> &visible, const tmx::Map& source)
    {
        // Let's build tilesets
        for(auto tileset : source.getTilesets())
            tilesets.push_back(Tileset(tileset));
           
        // The following part assumes we have only one tileset 
        unsigned tilesetwidth = tilesets[0].image.getSize().x / tilesets[0].tilewidth;

        int i = 0;
        for(auto layer : source.getLayers())
        {
            int j = 0;
            layers.push_back(std::vector<Tile>());
            visible.push_back(layer->getVisible());
            for(auto tile : layer->getData())
            {
                // Position of the tile on the tileset
                sf::Vector2i post(((tile.getId() - tilesets[0].firstgid) % tilesetwidth) * tilesets[0].tilewidth,
                                  ((tile.getId()-tilesets[0].firstgid) / tilesetwidth) * tilesets[0].tileheight
                                 );
                // Dimensions of the tile according to the tileset
                sf::Vector2i dim(tilesets[0].tilewidth, tilesets[0].tileheight);
                
                sf::IntRect rec(post, dim);
                
                // Position of the tile on the view
                sf::Vector2f pos((j % source.getWidth()) * tilesets[0].tilewidth, (j / source.getWidth()) * tilesets[0].tileheight);
                
                layers[i].push_back(Tile(tilesets[0].image, rec, pos));
                j++;
            }
            i++;
        }
        
        for(auto objectgroup : source.getObjectgroups())      
        {
            layers.push_back(std::vector<Tile>());
            for(auto object : *objectgroup)
            {
                // Position of the object on the tileset
                sf::Vector2i post(((object.getId() - tilesets[0].firstgid) % tilesetwidth) * tilesets[0].tilewidth,
                                  ((object.getId()-tilesets[0].firstgid) / tilesetwidth) * tilesets[0].tileheight
                                 );
                                 
                // Dimensions of the object according to the tileset                 
                sf::Vector2i dim(tilesets[0].tilewidth, tilesets[0].tileheight);
                
                sf::IntRect rec(post, dim);
                
                // Position of the tile on the view. Do NOT forget the offset due to Tile Map Editor positioning conventions.
                sf::Vector2f pos(object.getX(),object.getY()-tilesets[0].tileheight);
                
                layers[i].push_back(Tile(tilesets[0].image, rec, pos));
            }
        }
    }
开发者ID:aquemy,项目名称:TMXLib,代码行数:57,代码来源:map.cpp


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