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


C++ TileLayer::setMapWidth方法代码示例

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


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

示例1: parseTileLayer

void LevelParser::parseTileLayer(XMLElement* pTileElement, Level *pLevel)
{
	// New TileLayer instance 
	TileLayer* pTileLayer = new TileLayer(m_tileSize, m_width, m_height, TheGame::Instance().getTilesets());

	// local temporary variable
	bool collidable = false;

	// A multidimensional array of int values to hold our final decoded and uncompressed tile data
	std::vector<std::vector<int>> data;

	// xml data node
	XMLElement* pDataNode = nullptr;
	// to store base64 decoded information
	std::string decodedIDs;	

	// We search for the node we need
	for (XMLElement* e = pTileElement->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
	{
		// check if layer has properties
		if (e->Value() == std::string("properties"))
		{
			for (XMLElement* property = e->FirstChildElement(); property != NULL; property = property->NextSiblingElement())
			{
				if (property->Value() == std::string("property"))
				{
					// Check if it is a collision layer
					if (property->Attribute("name") == std::string("collidable"))
					{
						collidable = true;
					}
				}
			}
		}

		if (e->Value() == std::string("data"))
		{
			pDataNode = e;
		}
	}

	// Tile information not encoded nor compressed
	if (pDataNode->Attribute("encoding") == nullptr)
	{
		std::vector<int> layerRow(m_width);
		for (int rows = 0; rows < m_height; rows++)
		{
			data.push_back(layerRow);
		}

		XMLElement* tile = pDataNode->FirstChildElement();
		int id;
		for (int rows = 0; rows < m_height; rows++)
		{
			for (int cols = 0; cols < m_width ; cols++)
			{
				tile->QueryAttribute("gid", &data[rows][cols]);
				tile = tile->NextSiblingElement();
			}
		}
	}
	else
	{
		// We get the text (our encoded/compressed data) from the data node and use the base64 decoder to decode it
		for (XMLNode* e = pDataNode->FirstChild(); e != NULL; e = e->NextSibling())
		{
			XMLText* text = e->ToText();
			std::string t = text->Value();
			decodedIDs = base64_decode(t);
		}

		// We use the zlib library to decompress our data once again
		uLongf sizeofids = m_width * m_height * sizeof(int);
		std::vector<unsigned> gids(sizeofids);
		uncompress((Bytef*)&gids[0], &sizeofids, (const Bytef*)decodedIDs.c_str(), decodedIDs.size());

		// gids now contains all of our tile IDs, so we fill our data array with the correct values

		std::vector<int> layerRow(m_width);

		for (int j = 0; j < m_height; j++)
		{
			data.push_back(layerRow);
		}

		for (int rows = 0; rows < m_height; rows++)
		{
			for (int cols = 0; cols < m_width; cols++)
			{
				data[rows][cols] = gids[rows * m_width + cols];
			}
		}
	}

	pTileLayer->setTileIDs(data);
	pTileLayer->setMapWidth(m_width);

	// push into collision array and mark the layer as collidable if necessary
	if (collidable)
	{
//.........这里部分代码省略.........
开发者ID:afrosistema,项目名称:S2PEditor,代码行数:101,代码来源:LevelParser.cpp


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