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


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

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


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

示例1: writeSoloTileset

void TMXSceneEncoder::writeSoloTileset(const TMXMap& map, const gameplay::TMXTileSet& tmxTileset, const TMXLayer& tileset, std::ofstream& file, unsigned int resultOnlyForTileset)
{
    WRITE_PROPERTY_BLOCK_START("tileset");

    // Write tile path
    WRITE_PROPERTY_BLOCK_VALUE("path", tmxTileset.getImagePath());
    WRITE_PROPERTY_NEWLINE();

    // Write tile size
    //XXX if tile sizes are incorrect, make sure to update TMXLayer::getTileStart too
    char buffer[BUFFER_SIZE];
    snprintf(buffer, BUFFER_SIZE, "tileWidth = %u", tmxTileset.getMaxTileWidth());
    WRITE_PROPERTY_DIRECT(buffer);
    snprintf(buffer, BUFFER_SIZE, "tileHeight = %u", tmxTileset.getMaxTileHeight());
    WRITE_PROPERTY_DIRECT(buffer);

    // Write tileset size
    snprintf(buffer, BUFFER_SIZE, "columns = %u", tileset.getWidth());
    WRITE_PROPERTY_DIRECT(buffer);
    snprintf(buffer, BUFFER_SIZE, "rows = %u", tileset.getHeight());
    WRITE_PROPERTY_DIRECT(buffer);
    WRITE_PROPERTY_NEWLINE();

    // Write opacity
    if (tileset.getOpacity() < 1.0f)
    {
        snprintf(buffer, BUFFER_SIZE, "opacity = %f", tileset.getOpacity());
        WRITE_PROPERTY_DIRECT(buffer);
        WRITE_PROPERTY_NEWLINE();
    }

    // Write tiles
    unsigned int tilesetHeight = tileset.getHeight();
    unsigned int tilesetWidth = tileset.getWidth();
    for (unsigned int y = 0; y < tilesetHeight; y++)
    {
        bool tilesWritten = false;
        for (unsigned int x = 0; x < tilesetWidth; x++)
        {
            Vector2 startPos = tileset.getTileStart(x, y, map, resultOnlyForTileset);
            if (startPos.x < 0 || startPos.y < 0)
            {
                continue;
            }

            tilesWritten = true;
            WRITE_PROPERTY_BLOCK_START("tile");
            snprintf(buffer, BUFFER_SIZE, "cell = %u, %u", x, y);
            WRITE_PROPERTY_DIRECT(buffer);
            snprintf(buffer, BUFFER_SIZE, "source = %u, %u", static_cast<unsigned int>(startPos.x), static_cast<unsigned int>(startPos.y));
            WRITE_PROPERTY_DIRECT(buffer);
            WRITE_PROPERTY_BLOCK_END();
        }
        if (tilesWritten && ((y + 1) != tilesetHeight))
        {
            WRITE_PROPERTY_NEWLINE();
        }
    }

    WRITE_PROPERTY_BLOCK_END();
}
开发者ID:03050903,项目名称:GamePlay,代码行数:61,代码来源:TMXSceneEncoder.cpp

示例2: parseTmx


//.........这里部分代码省略.........
        {
            LOG(1, "Could not find <image> element for tileset.\n");
            return false;
        }
        tileSet.setImagePath(xmlTileSetImage->Attribute("source"));

        if (xmlTileSetImage->Attribute("width") && xmlTileSetImage->Attribute("height"))
        {
            attValue = xmlTileSetImage->Attribute("width");
            sscanf(attValue, "%u", &uiValue);
            tileSet.setImageWidth(uiValue);

            attValue = xmlTileSetImage->Attribute("height");
            sscanf(attValue, "%u", &uiValue);
            tileSet.setImageHeight(uiValue);
        }
        else
        {
            // Load the image itself to get the width
            string imageLocation = buildFilePath(inputDirectory, tileSet.getImagePath());
            int pos = imageLocation.find_last_of('.');
            if (imageLocation.substr(pos).compare(".png") != 0)
            {
                LOG(1, "TileSet image must be a PNG. %s\n", imageLocation.c_str());
                return false;
            }

            Image* img = Image::create(imageLocation.c_str());
            if (!img)
            {
                LOG(1, "Could not load TileSet image. %s\n", imageLocation.c_str());
                return false;
            }
            tileSet.setImageWidth(img->getWidth());
            tileSet.setImageHeight(img->getHeight());
            SAFE_DELETE(img);
        }

        //TODO: tiles (specifically, tile animations) if possible. May require marking tiles as special tiles, and spinning them off to Sprites
        //<tile id="relId"><animation><frame tileid="relId" duration="numInMS"></...></...></...>

        // Save the tileset
        map.addTileSet(tileSet);

        xmlTileSet = xmlTileSet->NextSiblingElement("tileset");
    }

    // Load the layers
    const XMLElement* xmlLayer = xmlMap->FirstChildElement("layer");
    while (xmlLayer)
    {
        TMXLayer* layer = new TMXLayer();

        parseBaseLayerProperties(xmlLayer, layer);

        // Load properties
        attValue = xmlLayer->Attribute("width");
        if (attValue)
        {
            sscanf(attValue, "%u", &uiValue);
            layer->setWidth(uiValue);
        }
        else
        {
            layer->setWidth(map.getWidth());
        }
开发者ID:03050903,项目名称:GamePlay,代码行数:67,代码来源:TMXSceneEncoder.cpp


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