本文整理汇总了C++中Tile::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ Tile::Parse方法的具体用法?C++ Tile::Parse怎么用?C++ Tile::Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tile
的用法示例。
在下文中一共展示了Tile::Parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseElement
void Tileset::ParseElement(const TiXmlElement *tilesetElem)
{
// Read all the attributes into local variables.
tilesetElem->Attribute("tilewidth", &tile_width);
tilesetElem->Attribute("tileheight", &tile_height);
tilesetElem->Attribute("margin", &margin);
tilesetElem->Attribute("spacing", &spacing);
char const *rawName = tilesetElem->Attribute("name");
name = (rawName == NULL) ? "" : rawName;
// Parse the image.
const TiXmlNode *imageNode = tilesetElem->FirstChild("image");
if (imageNode)
{
image = new Image();
image->Parse(imageNode);
}
// Iterate through all of the tile elements and parse each.
const TiXmlNode *tileNode = tilesetElem->FirstChild("tile");
while (tileNode)
{
// Allocate a new tile and parse it.
Tile *tile = new Tile();
tile->Parse(tileNode);
// Add the tile to the collection.
tiles.push_back(tile);
tileNode = tilesetElem->IterateChildren("tile", tileNode);
}
}
示例2: Parse
void Tileset::Parse(const tinyxml2::XMLNode *tilesetNode)
{
const tinyxml2::XMLElement *tilesetElem = tilesetNode->ToElement();
// Read all the attributes into local variables.
first_gid = tilesetElem->IntAttribute("firstgid");
tile_width = tilesetElem->IntAttribute("tilewidth");
tile_height = tilesetElem->IntAttribute("tileheight");
margin = tilesetElem->IntAttribute("margin");
spacing = tilesetElem->IntAttribute("spacing");
name = tilesetElem->Attribute("name");
// Parse the image.
const tinyxml2::XMLNode *imageNode = tilesetNode->FirstChildElement("image");
if (imageNode)
{
image = new Image();
image->Parse(imageNode);
}
// Populate the tile list
int tileCount = (image->GetWidth() / tile_width) * (image->GetHeight() / tile_height);
int tId = tiles.size();
while (tId < tileCount)
{
Tile* tile = new Tile(tId);
tiles.push_back(tile);
tId++;
}
// Iterate through all of the tile elements and parse each.
const tinyxml2::XMLNode *tileNode = tilesetNode->FirstChildElement("tile");
while (tileNode)
{
// Parse it to get the tile id.
Tile tile;
tile.Parse(tileNode);
// Using the ID in the temporary tile get the real tile and parse for real.
tiles[tile.GetId()]->Parse(tileNode);
//tileNode = tilesetNode->IterateChildren("tile", tileNode); FIXME MAYBE
tileNode = tileNode->NextSiblingElement("tile");
}
// Parse the properties if any.
const tinyxml2::XMLNode *propertiesNode = tilesetNode->FirstChildElement("properties");
if (propertiesNode)
{
properties.Parse(propertiesNode);
}
}
示例3: Parse
void Tileset::Parse(const TiXmlNode *tilesetNode)
{
const TiXmlElement *tilesetElem = tilesetNode->ToElement();
// Read all the attributes into local variables.
tilesetElem->Attribute("firstgid", &first_gid);
tilesetElem->Attribute("tilewidth", &tile_width);
tilesetElem->Attribute("tileheight", &tile_height);
tilesetElem->Attribute("margin", &margin);
tilesetElem->Attribute("spacing", &spacing);
name = tilesetElem->Attribute("name");
// Parse the image.
const TiXmlNode *imageNode = tilesetNode->FirstChild("image");
if (imageNode)
{
image = new Image();
image->Parse(imageNode);
}
// Iterate through all of the tile elements and parse each.
const TiXmlNode *tileNode = tilesetNode->FirstChild("tile");
while (tileNode)
{
// Allocate a new tile and parse it.
Tile *tile = new Tile();
tile->Parse(tileNode);
// Add the tile to the collection.
tiles.push_back(tile);
tileNode = tilesetNode->IterateChildren("tile", tileNode);
}
// Parse the properties if any.
const TiXmlNode *propertiesNode = tilesetNode->FirstChild("properties");
if (propertiesNode)
{
properties.Parse(propertiesNode);
}
}
示例4: Parse
void Tileset::Parse(const tinyxml2::XMLNode *tilesetNode, const std::string& file_path)
{
const tinyxml2::XMLElement *tilesetElem = tilesetNode->ToElement();
// Read all the attributes into local variables.
// The firstgid and source attribute are kept in the TMX map,
// since they are map specific.
first_gid = tilesetElem->IntAttribute("firstgid");
// If the <tileset> node contains a 'source' tag,
// the tileset config should be loaded from an external
// TSX (Tile Set XML) file. That file has the same structure
// as the <tileset> element in the TMX map.
const char* source_name = tilesetElem->Attribute("source");
tinyxml2::XMLDocument tileset_doc;
if ( source_name )
{
std::string fileName = file_path + source_name;
tileset_doc.LoadFile( fileName.c_str() );
if ( tileset_doc.ErrorID() != 0)
{
fprintf(stderr, "failed to load tileset file '%s'\n", fileName.c_str());
return;
}
// Update node and element references to the new node
tilesetNode = tileset_doc.FirstChildElement("tileset");
tilesetElem = tilesetNode->ToElement();
}
tile_width = tilesetElem->IntAttribute("tilewidth");
tile_height = tilesetElem->IntAttribute("tileheight");
margin = tilesetElem->IntAttribute("margin");
spacing = tilesetElem->IntAttribute("spacing");
name = tilesetElem->Attribute("name");
// Parse the tile offset, if it exists.
const tinyxml2::XMLNode *tileOffsetNode = tilesetNode->FirstChildElement("tileoffset");
if (tileOffsetNode)
{
tileOffset = new TileOffset();
tileOffset->Parse(tileOffsetNode);
}
// Parse the terrain types if any.
const tinyxml2::XMLNode *terrainTypesNode = tilesetNode->FirstChildElement("terraintypes");
if (terrainTypesNode)
{
TerrainArray terrainArray;
terrainArray.Parse(&terrainTypes, terrainTypesNode);
}
// Parse the image.
const tinyxml2::XMLNode *imageNode = tilesetNode->FirstChildElement("image");
if (imageNode)
{
image = new Image();
image->Parse(imageNode);
}
// Iterate through all of the tile elements and parse each.
const tinyxml2::XMLNode *tileNode = tilesetNode->FirstChildElement("tile");
for (int tId = 0; tileNode; ++tId)
{
Tile* tile = new Tile(tId);
tile->Parse(tileNode);
tiles.push_back(tile);
tileNode = tileNode->NextSiblingElement("tile");
}
// Parse the properties if any.
const tinyxml2::XMLNode *propertiesNode = tilesetNode->FirstChildElement("properties");
if (propertiesNode)
{
properties.Parse(propertiesNode);
}
}
示例5: Parse
void Tileset::Parse(const TiXmlNode *tilesetNode)
{
const TiXmlElement *tilesetElem = tilesetNode->ToElement();
// Read all the attributes into local variables.
tilesetElem->Attribute("firstgid", &first_gid);
tilesetElem->Attribute("tilewidth", &tile_width);
tilesetElem->Attribute("tileheight", &tile_height);
tilesetElem->Attribute("margin", &margin);
tilesetElem->Attribute("spacing", &spacing);
name = tilesetElem->Attribute("name");
// IGNACIO CEA
// Parser the offset
const TiXmlNode *offsetNode = tilesetNode->FirstChild("tileoffset");
if (offsetNode)
{
const TiXmlElement *offsetElement = offsetNode->ToElement();
offsetElement->Attribute("x", &x_offset);
offsetElement->Attribute("y", &y_offset);
}
// IGNACIO CEA
// Parse the image.
const TiXmlNode *imageNode = tilesetNode->FirstChild("image");
if (imageNode)
{
image = new Image();
image->Parse(imageNode);
}
// Populate the tile list
int tileCount = (image->GetWidth() / tile_width) * (image->GetHeight() / tile_height);
int tId = tiles.size();
while (tId < tileCount)
{
Tile* tile = new Tile(tId);
tiles.push_back(tile);
tId++;
}
// Iterate through all of the tile elements and parse each.
const TiXmlNode *tileNode = tilesetNode->FirstChild("tile");
while (tileNode)
{
// Parse it to get the tile id.
Tile tile;
tile.Parse(tileNode);
// Using the ID in the temporary tile get the real tile and parse for real.
tiles[tile.GetId()]->Parse(tileNode);
tileNode = tilesetNode->IterateChildren("tile", tileNode);
}
// Parse the properties if any.
const TiXmlNode *propertiesNode = tilesetNode->FirstChild("properties");
if (propertiesNode)
{
properties.Parse(propertiesNode);
}
}