本文整理汇总了C++中CCTMXMapInfo::getTMXFileName方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXMapInfo::getTMXFileName方法的具体用法?C++ CCTMXMapInfo::getTMXFileName怎么用?C++ CCTMXMapInfo::getTMXFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTMXMapInfo
的用法示例。
在下文中一共展示了CCTMXMapInfo::getTMXFileName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startElement
// the XML parser calls here with all the elements
void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
{
CC_UNUSED_PARAM(ctx);
CCTMXMapInfo *pTMXMapInfo = this;
std::string elementName = (char*)name;
std::map<std::string, std::string> *attributeDict = new std::map<std::string, std::string>();
if(atts && atts[0])
{
for(int i = 0; atts[i]; i += 2)
{
std::string key = (char*)atts[i];
std::string value = (char*)atts[i+1];
attributeDict->insert(pair<std::string, std::string>(key, value));
}
}
if(elementName == "map")
{
std::string version = valueForKey("version", attributeDict);
if ( version != "1.0")
{
CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %@", version.c_str());
}
std::string orientationStr = valueForKey("orientation", attributeDict);
if( orientationStr == "orthogonal")
pTMXMapInfo->setOrientation(CCTMXOrientationOrtho);
else if ( orientationStr == "isometric")
pTMXMapInfo->setOrientation(CCTMXOrientationIso);
else if( orientationStr == "hexagonal")
pTMXMapInfo->setOrientation(CCTMXOrientationHex);
else
CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", pTMXMapInfo->getOrientation());
CCSize s;
s.width = (float)atof(valueForKey("width", attributeDict));
s.height = (float)atof(valueForKey("height", attributeDict));
pTMXMapInfo->setMapSize(s);
s.width = (float)atof(valueForKey("tilewidth", attributeDict));
s.height = (float)atof(valueForKey("tileheight", attributeDict));
pTMXMapInfo->setTileSize(s);
// The parent element is now "map"
pTMXMapInfo->setParentElement(TMXPropertyMap);
}
else if(elementName == "tileset")
{
// If this is an external tileset then start parsing that
std::string externalTilesetFilename = valueForKey("source", attributeDict);
if (externalTilesetFilename != "")
{
if (m_sTMXFileName.length() == 0)
{
string pszFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(m_sResources.c_str());
if (pszFullPath.find_last_of("/\\") != pszFullPath.length()-1)
{
pszFullPath.append("/");
}
externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(externalTilesetFilename.c_str(), pszFullPath.c_str() );
}
else
{
externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(externalTilesetFilename.c_str(), pTMXMapInfo->getTMXFileName());
}
pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str());
}
else
{
CCTMXTilesetInfo *tileset = new CCTMXTilesetInfo();
tileset->m_sName = valueForKey("name", attributeDict);
tileset->m_uFirstGid = (unsigned int)atoi(valueForKey("firstgid", attributeDict));
tileset->m_uSpacing = (unsigned int)atoi(valueForKey("spacing", attributeDict));
tileset->m_uMargin = (unsigned int)atoi(valueForKey("margin", attributeDict));
CCSize s;
s.width = (float)atof(valueForKey("tilewidth", attributeDict));
s.height = (float)atof(valueForKey("tileheight", attributeDict));
tileset->m_tTileSize = s;
pTMXMapInfo->getTilesets()->addObject(tileset);
tileset->release();
}
}
else if(elementName == "tile")
{
CCTMXTilesetInfo* info = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();
CCDictionary *dict = new CCDictionary();
pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict)));
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
CC_SAFE_RELEASE(dict);
pTMXMapInfo->setParentElement(TMXPropertyTile);
}
else if(elementName == "layer")
{
CCTMXLayerInfo *layer = new CCTMXLayerInfo();
layer->m_sName = valueForKey("name", attributeDict);
CCSize s;
//.........这里部分代码省略.........