本文整理汇总了C++中Tileset::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::Parse方法的具体用法?C++ Tileset::Parse怎么用?C++ Tileset::Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tileset
的用法示例。
在下文中一共展示了Tileset::Parse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 )
{
//.........这里部分代码省略.........
示例2: 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();
}
}
示例3: 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;
}
else if (!orientationStr.compare("staggered"))
{
orientation = TMX_MO_STAGGERED;
}
const TiXmlNode *node = mapElem->FirstChild();
int zOrder = 0;
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 elements.
if( strcmp( node->Value(), "layer" ) == 0 )
{
// Allocate a new layer and parse it.
Layer *layer = new Layer(this);
layer->Parse(node);
layer->SetZOrder( zOrder );
++zOrder;
// Add the layer to the list.
layers.push_back(layer);
}
// Iterate through all of the imagen layer elements.
if( strcmp( node->Value(), "imagelayer" ) == 0 )
{
// Allocate a new layer and parse it.
ImageLayer *imageLayer = new ImageLayer(this);
imageLayer->Parse(node);
imageLayer->SetZOrder( zOrder );
++zOrder;
// Add the layer to the list.
image_layers.push_back(imageLayer);
}
// Iterate through all of the objectgroup elements.
if( strcmp( node->Value(), "objectgroup" ) == 0 )
{
// Allocate a new object group and parse it.
ObjectGroup *objectGroup = new ObjectGroup();
objectGroup->Parse(node);
objectGroup->SetZOrder( zOrder );
++zOrder;
// Add the object group to the list.
object_groups.push_back(objectGroup);
//.........这里部分代码省略.........
示例4: 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);
//.........这里部分代码省略.........