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


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

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


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

示例1: tilesetForLayer

// private
TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
    TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
    TMXLayer *layer = TMXLayer::create(tileset, layerInfo, mapInfo);

    // tell the layerinfo to release the ownership of the tiles map.
    layerInfo->_ownTiles = false;
    layer->setupTiles();

    return layer;
}
开发者ID:mixiancheng,项目名称:selfWork,代码行数:12,代码来源:CCFastTMXTiledMap.cpp

示例2: parseTmx


//.........这里部分代码省略.........
            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());
        }

        attValue = xmlLayer->Attribute("height");
        if (attValue)
        {
            sscanf(attValue, "%u", &uiValue);
            layer->setHeight(uiValue);
        }
        else
        {
            layer->setHeight(map.getHeight());
        }

        // Load tiles
        layer->setupTiles();
        auto data = loadDataElement(xmlLayer->FirstChildElement("data"));
        size_t dataSize = data.size();
        for (int i = 0; i < dataSize; i++)
        {
            //XXX this might depend on map's renderorder... not sure
            unsigned int x = i % layer->getWidth();
            unsigned int y = i / layer->getWidth();
            layer->setTile(x, y, data[i]);
        }

        // Save layer
        map.addLayer(layer);

        xmlLayer = xmlLayer->NextSiblingElement("layer");
    }

    // Load image layers
    const XMLElement* xmlImgLayer = xmlMap->FirstChildElement("imagelayer");
    while (xmlImgLayer)
    {
        TMXImageLayer* imgLayer = new TMXImageLayer();

        parseBaseLayerProperties(xmlImgLayer, imgLayer);

        // Load properties
        attValue = xmlImgLayer->Attribute("x");
        if (attValue)
        {
            sscanf(attValue, "%d", &iValue);
            imgLayer->setX(iValue);
        }
        attValue = xmlImgLayer->Attribute("y");
        if (attValue)
        {
            sscanf(attValue, "%d", &iValue);
            imgLayer->setY(iValue);
        }

        // Load image source. Don't worry about <data>, trans, width, or height
        const XMLElement* xmlImage = xmlImgLayer->FirstChildElement("image");
        if (!xmlImage)
        {
            LOG(1, "Could not find <image> element for the image layer.\n");
            return false;
        }
        imgLayer->setImagePath(xmlImage->Attribute("source"));

        // Save image layer
        map.addLayer(imgLayer);

        xmlImgLayer = xmlImgLayer->NextSiblingElement("imagelayer");
    }

    return true;
}
开发者ID:03050903,项目名称:GamePlay,代码行数:101,代码来源:TMXSceneEncoder.cpp


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