本文整理汇总了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;
}
示例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;
}