本文整理汇总了C++中TileSet::addTile方法的典型用法代码示例。如果您正苦于以下问题:C++ TileSet::addTile方法的具体用法?C++ TileSet::addTile怎么用?C++ TileSet::addTile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileSet
的用法示例。
在下文中一共展示了TileSet::addTile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doParsing
Map* Parseur::doParsing()
{
Field* fieldLayer;
std::vector<ObjectLayers*> layersObjects;
xml_node mapXml = doc_.child("map");
int mapWidth = mapXml.attribute("width").as_int();
int mapHeight = mapXml.attribute("height").as_int();
std::string orientation(mapXml.attribute("orientation").value());
//"Header" TMX file parsing (tileset tags)
xml_node firstTileSetXml = mapXml.child("tileset");
std::vector<TileSet*> ensTileSet;
for(xml_node aTileSet = firstTileSetXml; aTileSet; aTileSet = aTileSet.next_sibling("tileset"))
{
//create new tileSetImage
xml_node tilsetImageXml = aTileSet.child("image");
TileSetImage* tsi = createTileSetImage(tilsetImageXml.attribute("source").value(), tilsetImageXml.attribute("width").as_int(), tilsetImageXml.attribute("height").as_int());
//create new tileSet with given attributs.
TileSet* ts = createTileSet(aTileSet.attribute("firstgid").as_int(), aTileSet.attribute("name").value(), aTileSet.attribute("tilewidth").as_int(), aTileSet.attribute("tileheight").as_int(), tsi);
//get tile tags
xml_node firstTileXml = aTileSet.child("tile");
for(xml_node aTile = firstTileXml; aTile; aTile = aTile.next_sibling("tile"))
{
//foreach tile tags create new tile
Tile* tile = createTile(aTile.attribute("id").as_int(), ts, ts->getNbTilePerRow());
// std::cout << "tileId : " << aTile.attribute("id").as_int() << " :" << std::endl;
xml_node firstTileProperty = aTile.child("properties").child("property");
for(xml_node aProperty = firstTileProperty; aProperty; aProperty = aProperty.next_sibling("property"))
{
//get property tags and add it to tile object
char* name;
name = new char[strlen(aProperty.attribute("name").value())+1];
strcpy(name, aProperty.attribute("name").value());
char* value;
value = new char[strlen(aProperty.attribute("value").value())];
strcpy(value, aProperty.attribute("value").value());
tile->addProperty(name, value);
// std::cout << "\t property " << name << " = " << value << std::endl;
}
ts->addTile(tile);
ensTileSet.push_back(ts);
}
}
//parsing layers
xml_node firstLayerXml = mapXml.child("layer");
Field* field;
int x;
int y;
for(xml_node aLayer = firstLayerXml; aLayer; aLayer = aLayer.next_sibling("layer"))
{
// std::cout << aLayer.attribute("name").value() << std::endl;
ensCells cellsMap;
xml_node firstCellXml = aLayer.child("data").child("tile");
x = 0;
y = 0;
for(xml_node aCellXml = firstCellXml; aCellXml; aCellXml = aCellXml.next_sibling("tile"))
{
int gid = aCellXml.attribute("gid").as_int();
//get Tile with the current gid
Tile* t;
bool get = false;
TileSet* currentTileSet;
std::vector<TileSet*>::iterator it = ensTileSet.begin();
Obstacle* obstacle;
while(it != ensTileSet.end() && !get)
{
t = (*it)->getTile(gid-(*it)->getFirstGid());
currentTileSet = (*it);
if((*t)!=Tile())
{
obstacle = mapFactory_->createObstacle(t, t->getTileId(), t->getPropertyValue("type"), t->getProperties());
get = true;
// std::cout << t->getTileId() << std::endl;
}
++it;
}
if(!get)
{
obstacle = new Obstacle();
}
//pour créer un obstacle il faut un TileSet, un tileId, le type (Field, object, fixed), les propriété
//Pour récupérer les Cells du layers, il faut un Obstacle et la position de la cellule
Cell* cell = mapFactory_->createCell(x, y, obstacle);
// std::cout << *cell << std::endl;
cellsMap.insert(std::pair< std::pair<int, int>, Cell*>(std::pair<int, int>(x,y), cell));
// std::cout << "(" << x << ", " << y << ") : tileId = " << t->getTileId() << std::endl;
//
////
x++;
if(x >= mapWidth)
{
x=0;
y++;
}
// //normaly, when x=mapWidth and y=mapHeight we have finished to parse this layer
//.........这里部分代码省略.........