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


C++ Tilemap::SetTile方法代码示例

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


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

示例1: Load

	void Level::Load(const std::string &filename, Scene* scene)
	{
		// load from an xml file, into the scene

		if (scene != NULL)
		{
			instance->scene = scene;
		}

		if (instance->scene)
		{
			// unload tilemaps... (need to destroy them?)
			instance->tilemaps.clear();
			//clearfringeTileset

			TiXmlDocument xml(Assets::GetContentPath() + filename);
			instance->filename = filename;
			bool isLoaded = xml.LoadFile();

			if (isLoaded)
			{
				TiXmlElement* eLevel = xml.FirstChildElement("Level");
				if (eLevel)
				{
					instance->width = XMLReadInt(eLevel, "width");
					instance->height = XMLReadInt(eLevel, "height");

					TiXmlElement *eTilemap = eLevel->FirstChildElement("Tilemap");
					while (eTilemap)
					{
						Entity *entity = new Entity();
						Tilemap *tilemap = new Tilemap(instance->GetTilesetByName(XMLReadString(eTilemap, "set")), instance->width, instance->height, XMLReadInt(eTilemap, "tileWidth"), XMLReadInt(eTilemap, "tileHeight"));
						instance->tilemaps.push_back(tilemap);
						entity->SetGraphic(tilemap);
						instance->scene->Add(entity);

						TiXmlElement *eTile = eTilemap->FirstChildElement("Tile");
						while (eTile)
						{
							tilemap->SetTile(XMLReadInt(eTile, "x"), XMLReadInt(eTile, "y"), XMLReadInt(eTile, "tileID"));
							eTile = eTile->NextSiblingElement("Tile");
						}
						eTilemap = eTilemap->NextSiblingElement("Tilemap");
					}

					TiXmlElement *eFringeTiles = eLevel->FirstChildElement("FringeTiles");
					while (eFringeTiles)
					{
						FringeTileset *fringeTileset = instance->GetFringeTilesetByName(XMLReadString(eFringeTiles, "set"));

						/*
						Entity *entity = new Entity();
						Tilemap *tilemap = new Tilemap(instance->GetTileset(XMLString(eTilemap, "set")), instance->width, instance->height, XMLInt(eTilemap, "tileWidth"), XMLInt(eTilemap, "tileHeight"));
						instance->tilemaps.push_back(tilemap);
						entity->SetGraphic(tilemap);
						instance->scene->Add(entity);
						*/

						if (fringeTileset)
						{
							TiXmlElement *eFringeTile = eFringeTiles->FirstChildElement("FringeTile");
							while (eFringeTile)
							{
								int tileID = XMLReadInt(eFringeTile, "id");

								int layer = XMLReadInt(eFringeTile, "layer");

								Vector2 position = Vector2(XMLReadFloat(eFringeTile, "x"), XMLReadFloat(eFringeTile, "y"));

								Vector2 scale = Vector2::one;

								if (eFringeTile->Attribute("scaleX") != NULL && eFringeTile->Attribute("scaleY") != NULL)
									scale = Vector2(XMLReadFloat(eFringeTile, "scaleX"), XMLReadFloat(eFringeTile, "scaleY"));

								int rotation = XMLReadFloat(eFringeTile, "rotation");

								Color color = Color::white;
								if (eFringeTile->Attribute("ca"))
								{
									color.a = XMLReadFloat(eFringeTile, "ca");
								}

								AddFringeTile(fringeTileset, tileID, layer, position, scale, rotation, color);

								eFringeTile = eFringeTile->NextSiblingElement("FringeTile");
							}
						}

						eFringeTiles = eFringeTiles->NextSiblingElement("FringeTiles");
					}
				}
			}
					
		}
	}
开发者ID:FrozenCow,项目名称:Monocle-Engine,代码行数:95,代码来源:Level.cpp


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