本文整理汇总了C++中TMXMapInfo::setCurrentString方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXMapInfo::setCurrentString方法的具体用法?C++ TMXMapInfo::setCurrentString怎么用?C++ TMXMapInfo::setCurrentString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXMapInfo
的用法示例。
在下文中一共展示了TMXMapInfo::setCurrentString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: textHandler
void TMXMapInfo::textHandler(void *ctx, const char *ch, int len)
{
CC_UNUSED_PARAM(ctx);
TMXMapInfo *tmxMapInfo = this;
std::string text(ch, 0, len);
if (tmxMapInfo->isStoringCharacters())
{
std::string currentString = tmxMapInfo->getCurrentString();
currentString += text;
tmxMapInfo->setCurrentString(currentString);
}
}
示例2: endElement
void TMXMapInfo::endElement(void *ctx, const char *name)
{
CC_UNUSED_PARAM(ctx);
TMXMapInfo *tmxMapInfo = this;
std::string elementName = name;
if (elementName == "data")
{
if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
{
tmxMapInfo->setStoringCharacters(false);
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
std::string currentString = tmxMapInfo->getCurrentString();
unsigned char *buffer;
auto len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
if (!buffer)
{
CCLOG("cocos2d: TiledMap: decode data error");
return;
}
if (tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib))
{
unsigned char *deflated = nullptr;
Size s = layer->_layerSize;
// int sizeHint = s.width * s.height * sizeof(uint32_t);
ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);
ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
CCASSERT(inflatedLen == sizeHint, "inflatedLen should be equal to sizeHint!");
free(buffer);
buffer = nullptr;
if (!deflated)
{
CCLOG("cocos2d: TiledMap: inflate data error");
return;
}
layer->_tiles = reinterpret_cast<uint32_t*>(deflated);
}
else
{
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
}
tmxMapInfo->setCurrentString("");
}
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribNone)
{
_xmlTileIndex = 0;
}
}
else if (elementName == "map")
{
// The map element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "layer")
{
// The layer element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "objectgroup")
{
// The objectgroup element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "object")
{
// The object element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "tileset")
{
_recordFirstGID = true;
}
}
示例3: endElement
void TMXMapInfo::endElement(void *ctx, const char *name)
{
CC_UNUSED_PARAM(ctx);
TMXMapInfo *tmxMapInfo = this;
std::string elementName = name;
if (elementName == "data")
{
if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
{
tmxMapInfo->setStoringCharacters(false);
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
std::string currentString = tmxMapInfo->getCurrentString();
unsigned char *buffer;
auto len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
if (!buffer)
{
CCLOG("cocos2d: TiledMap: decode data error");
return;
}
if (tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib))
{
unsigned char *deflated = nullptr;
Size s = layer->_layerSize;
// int sizeHint = s.width * s.height * sizeof(uint32_t);
ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);
ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
CCASSERT(inflatedLen == sizeHint, "inflatedLen should be equal to sizeHint!");
free(buffer);
buffer = nullptr;
if (!deflated)
{
CCLOG("cocos2d: TiledMap: inflate data error");
return;
}
layer->_tiles = reinterpret_cast<uint32_t*>(deflated);
}
else
{
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
}
tmxMapInfo->setCurrentString("");
}
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribCSV)
{
unsigned char *buffer;
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
tmxMapInfo->setStoringCharacters(false);
std::string currentString = tmxMapInfo->getCurrentString();
vector<string> gidTokens;
istringstream filestr(currentString);
string sRow;
while(getline(filestr, sRow, '\n')) {
string sGID;
istringstream rowstr(sRow);
while (getline(rowstr, sGID, ',')) {
gidTokens.push_back(sGID);
}
}
// 32-bits per gid
buffer = (unsigned char*)malloc(gidTokens.size() * 4);
if (!buffer)
{
CCLOG("cocos2d: TiledMap: CSV buffer not allocated.");
return;
}
uint32_t* bufferPtr = reinterpret_cast<uint32_t*>(buffer);
for(auto gidToken : gidTokens) {
auto tileGid = (uint32_t)strtol(gidToken.c_str(), nullptr, 10);
*bufferPtr = tileGid;
bufferPtr++;
}
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
tmxMapInfo->setCurrentString("");
}
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribNone)
{
_xmlTileIndex = 0;
}
}
else if (elementName == "map")
{
// The map element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
//.........这里部分代码省略.........