本文整理汇总了C++中CCTMXMapInfo::getLayerAttribs方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXMapInfo::getLayerAttribs方法的具体用法?C++ CCTMXMapInfo::getLayerAttribs怎么用?C++ CCTMXMapInfo::getLayerAttribs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTMXMapInfo
的用法示例。
在下文中一共展示了CCTMXMapInfo::getLayerAttribs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: endElement
void CCTMXMapInfo::endElement(void *ctx, const char *name)
{
CC_UNUSED_PARAM(ctx);
CCTMXMapInfo *pTMXMapInfo = this;
std::string elementName = (char*)name;
int len = 0;
if(elementName == "data" && pTMXMapInfo->getLayerAttribs()&TMXLayerAttribBase64)
{
pTMXMapInfo->setStoringCharacters(false);
CCTMXLayerInfo* layer = (CCTMXLayerInfo*)pTMXMapInfo->getLayers()->lastObject();
std::string currentString = pTMXMapInfo->getCurrentString();
unsigned char *buffer;
len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
if( ! buffer )
{
CCLOG("cocos2d: TiledMap: decode data error");
return;
}
if( pTMXMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib) )
{
unsigned char *deflated;
CCSize s = layer->m_tLayerSize;
// int sizeHint = s.width * s.height * sizeof(uint32_t);
int sizeHint = (int)(s.width * s.height * sizeof(unsigned int));
int inflatedLen = ZipUtils::ccInflateMemoryWithHint(buffer, len, &deflated, sizeHint);
CCAssert(inflatedLen == sizeHint, "");
inflatedLen = (size_t)&inflatedLen; // XXX: to avoid warnings in compiler
delete [] buffer;
buffer = NULL;
if( ! deflated )
{
CCLOG("cocos2d: TiledMap: inflate data error");
return;
}
layer->m_pTiles = (unsigned int*) deflated;
}
else
{
layer->m_pTiles = (unsigned int*) buffer;
}
pTMXMapInfo->setCurrentString("");
}
else if (elementName == "map")
{
// The map element has ended
pTMXMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "layer")
{
// The layer element has ended
pTMXMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "objectgroup")
{
// The objectgroup element has ended
pTMXMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "object")
{
// The object element has ended
pTMXMapInfo->setParentElement(TMXPropertyNone);
}
}
示例2: startElement
//.........这里部分代码省略.........
objectGroup->setPositionOffset(positionOffset);
pTMXMapInfo->getObjectGroups()->addObject(objectGroup);
objectGroup->release();
// The parent element is now "objectgroup"
pTMXMapInfo->setParentElement(TMXPropertyObjectGroup);
}
else if (elementName == "image")
{
CCTMXTilesetInfo* tileset = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();
// build full path
std::string imagename = valueForKey("source", attributeDict);
if (m_sTMXFileName.find_last_of("/") != string::npos)
{
string dir = m_sTMXFileName.substr(0, m_sTMXFileName.find_last_of("/") + 1);
tileset->m_sSourceImage = dir + imagename;
}
else
{
tileset->m_sSourceImage = m_sResources + (m_sResources.size() ? "/" : "") + imagename;
}
}
else if (elementName == "data")
{
std::string encoding = valueForKey("encoding", attributeDict);
std::string compression = valueForKey("compression", attributeDict);
if( encoding == "base64" )
{
int layerAttribs = pTMXMapInfo->getLayerAttribs();
pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64);
pTMXMapInfo->setStoringCharacters(true);
if( compression == "gzip" )
{
layerAttribs = pTMXMapInfo->getLayerAttribs();
pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
} else
if (compression == "zlib")
{
layerAttribs = pTMXMapInfo->getLayerAttribs();
pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
}
CCAssert( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
}
CCAssert( pTMXMapInfo->getLayerAttribs() != TMXLayerAttribNone, "TMX tile map: Only base64 and/or gzip/zlib maps are supported" );
}
else if (elementName == "object")
{
char buffer[32] = {0};
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
// The value for "type" was blank or not a valid class name
// Create an instance of TMXObjectInfo to store the object and its properties
CCDictionary *dict = new CCDictionary();
// Parse everything automatically
const char* pArray[] = {"name", "type", "width", "height", "gid"};
for(size_t i = 0; i < sizeof(pArray)/sizeof(pArray[0]); ++i )
{
const char* key = pArray[i];