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


C++ Tile::addProperty方法代码示例

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


在下文中一共展示了Tile::addProperty方法的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
//.........这里部分代码省略.........
开发者ID:bmael,项目名称:I-rover,代码行数:101,代码来源:parseur.cpp


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