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


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

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


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

示例1: ParseText

	void Map::ParseText(const string &text) 
	{
		// Create a tiny xml document and use it to parse the text.
		TiXmlDocument doc;
		doc.Parse(text.c_str());
	
		// Check for parsing errors.
		if (doc.Error()) 
		{
			has_error = true;
			error_code = TMX_PARSING_ERROR;
			error_text = doc.ErrorDesc();
			return;
		}

		TiXmlNode *mapNode = doc.FirstChild("map");
		TiXmlElement* mapElem = mapNode->ToElement();

		// Read the map attributes.
		mapElem->Attribute("version", &version);
		mapElem->Attribute("width", &width);
		mapElem->Attribute("height", &height);
		mapElem->Attribute("tilewidth", &tile_width);
		mapElem->Attribute("tileheight", &tile_height);

		// Read the orientation
		std::string orientationStr = mapElem->Attribute("orientation");

		if (!orientationStr.compare("orthogonal")) 
		{
			orientation = TMX_MO_ORTHOGONAL;
		} 
		else if (!orientationStr.compare("isometric")) 
		{
			orientation = TMX_MO_ISOMETRIC;
		}

		// Read the map properties.
		const TiXmlNode *propertiesNode = mapElem->FirstChild("properties");
		if (propertiesNode) 
		{
			properties.Parse(propertiesNode);
		}

		// Iterate through all of the tileset elements.
		const TiXmlNode *tilesetNode = mapNode->FirstChild("tileset");
		while (tilesetNode) 
		{
			// Allocate a new tileset and parse it.
			Tileset *tileset = new Tileset();
			tileset->Parse(tilesetNode->ToElement());

			// Add the tileset to the list.
			tilesets.push_back(tileset);

			tilesetNode = mapNode->IterateChildren("tileset", tilesetNode);
		}

		// Find all layers and object groups.
		TiXmlNode *layerNode = mapNode->FirstChild();
		while( layerNode != 0 )
		{
			if( std::string("layer") == layerNode->Value() )
			{
				// Allocate a new layer and parse it.
				TileLayer *layer = new TileLayer(this);
				layer->Parse(layerNode);

				// Add the layer to the list.
				layers.push_back(layer);
			}

			if( std::string("objectgroup") == layerNode->Value() )
			{
				// Allocate a new object group and parse it.
				ObjectLayer *objectGroup = new ObjectLayer(this);
				objectGroup->Parse(layerNode);
		
				// Add the object group to the list.
				layers.push_back(objectGroup);
			}

			layerNode = layerNode->NextSibling();
		}
	}
开发者ID:EemeliSyynimaa,项目名称:yam2d,代码行数:85,代码来源:TmxMap.cpp

示例2: Parse

    void Map::Parse(tinyxml2::XMLNode *mapNode)
    {
        tinyxml2::XMLElement* mapElem = mapNode->ToElement();

        // Read the map attributes.
        version = mapElem->IntAttribute("version");
        width = mapElem->IntAttribute("width");
        height = mapElem->IntAttribute("height");
        tile_width = mapElem->IntAttribute("tilewidth");
        tile_height = mapElem->IntAttribute("tileheight");
        next_object_id = mapElem->IntAttribute("nextobjectid");

        if (mapElem->Attribute("backgroundcolor"))
        {
            background_color = mapElem->Attribute("backgroundcolor");
        }

        // Read the orientation
        std::string orientationStr = mapElem->Attribute("orientation");

        if (!orientationStr.compare("orthogonal"))
        {
            orientation = TMX_MO_ORTHOGONAL;
        } 
        else if (!orientationStr.compare("isometric"))
        {
            orientation = TMX_MO_ISOMETRIC;
        }
        else if (!orientationStr.compare("staggered"))
        {
            orientation = TMX_MO_STAGGERED;
        }
        else if (!orientationStr.compare("hexagonal"))
        {
            orientation = TMX_MO_HEXAGONAL;
        }

        // Read the render order
        if (mapElem->Attribute("renderorder"))
        {
            std::string renderorderStr = mapElem->Attribute("renderorder");
            if (!renderorderStr.compare("right-down")) 
            {
                render_order = TMX_RIGHT_DOWN;
            } 
            else if (!renderorderStr.compare("right-up")) 
            {
                render_order = TMX_RIGHT_UP;
            }
            else if (!renderorderStr.compare("left-down")) 
            {
                render_order = TMX_LEFT_DOWN;
            }
            else if (!renderorderStr.compare("left-down")) 
            {
                render_order = TMX_LEFT_UP;
            }        
        }

        // Read the stagger axis
        if (mapElem->Attribute("staggeraxis"))
        {
            std::string staggerAxisStr = mapElem->Attribute("staggeraxis");
            if (!staggerAxisStr.compare("x"))
            {
                stagger_axis = TMX_SA_X;
            }
            else if (!staggerAxisStr.compare("y"))
            {
                stagger_axis = TMX_SA_Y;
            }
        }

        // Read the stagger index
        if (mapElem->Attribute("staggerindex"))
        {
            std::string staggerIndexStr = mapElem->Attribute("staggerindex");
            if (!staggerIndexStr.compare("even"))
            {
                stagger_index = TMX_SI_EVEN;
            }
            else if (!staggerIndexStr.compare("odd"))
            {
                stagger_index = TMX_SI_ODD;
            }
        }

        // read the hexside length
        if (mapElem->IntAttribute("hexsidelength"))
        {
            hexside_length = mapElem->IntAttribute("hexsidelength");
        }

        // read all other attributes
        const tinyxml2::XMLNode *node = mapElem->FirstChild();
        while( node )
        {
            // Read the map properties.
            if( strcmp( node->Value(), "properties" ) == 0 )
            {
//.........这里部分代码省略.........
开发者ID:aquafox,项目名称:debuggame,代码行数:101,代码来源:TmxMap.cpp

示例3: ParseText

    void Map::ParseText(const string &text) 
    {
        // Create a tiny xml document and use it to parse the text.
        tinyxml2::XMLDocument doc;
        doc.Parse(text.c_str());
    
        // Check for parsing errors.
        if (doc.Error()) 
        {
            has_error = true;
            error_code = TMX_PARSING_ERROR;
            error_text = doc.GetErrorStr1();
            return;
        }

        tinyxml2::XMLNode *mapNode = doc.FirstChildElement("map");
        tinyxml2::XMLElement* mapElem = mapNode->ToElement();

        // Read the map attributes.
        version = mapElem->IntAttribute("version");
        width = mapElem->IntAttribute("width");
        height = mapElem->IntAttribute("height");
        tile_width = mapElem->IntAttribute("tilewidth");
        tile_height = mapElem->IntAttribute("tileheight");
        next_object_id = mapElem->IntAttribute("nextobjectid");

        if (mapElem->Attribute("backgroundcolor"))
        {
            background_color = mapElem->Attribute("backgroundcolor");
        }

        // Read the orientation
        std::string orientationStr = mapElem->Attribute("orientation");

        if (!orientationStr.compare("orthogonal")) 
        {
            orientation = TMX_MO_ORTHOGONAL;
        } 
        else if (!orientationStr.compare("isometric")) 
        {
            orientation = TMX_MO_ISOMETRIC;
        }
        else if (!orientationStr.compare("staggered")) 
        {
            orientation = TMX_MO_STAGGERED;
        }
        

        // Read the render order
        if (mapElem->Attribute("renderorder"))
        {
            std::string renderorderStr = mapElem->Attribute("renderorder");
            if (!renderorderStr.compare("right-down")) 
            {
                render_order = TMX_RIGHT_DOWN;
            } 
            else if (!renderorderStr.compare("right-up")) 
            {
                render_order = TMX_RIGHT_UP;
            }
            else if (!renderorderStr.compare("left-down")) 
            {
                render_order = TMX_LEFT_DOWN;
            }
            else if (!renderorderStr.compare("left-down")) 
            {
                render_order = TMX_LEFT_UP;
            }        
        }

        const tinyxml2::XMLNode *node = mapElem->FirstChild();
        while( node )
        {
            // Read the map properties.
            if( strcmp( node->Value(), "properties" ) == 0 )
            {
                properties.Parse(node);         
            }

            // Iterate through all of the tileset elements.
            if( strcmp( node->Value(), "tileset" ) == 0 )
            {
                // Allocate a new tileset and parse it.
                Tileset *tileset = new Tileset();
                tileset->Parse(node->ToElement());

                // Add the tileset to the list.
                tilesets.push_back(tileset);
            }

            // Iterate through all of the "layer" (tile layer) elements.           
            if( strcmp( node->Value(), "layer" ) == 0 )
            {
                // Allocate a new tile layer and parse it.
                TileLayer *tileLayer = new TileLayer(this);
                tileLayer->Parse(node);

                // Add the tile layer to the lists.
                tile_layers.push_back(tileLayer);
                layers.push_back(tileLayer);
//.........这里部分代码省略.........
开发者ID:vheuken,项目名称:tmxparser,代码行数:101,代码来源:TmxMap.cpp


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