我正在運行Coco2D-X的particleWithFile()函數,並使用Mac創建的plist文件。使用「textureImageData」鍵將圖像數據嵌入到plist文件中。 在Mac它工作正常,但與Windows失敗了,在CCAssert(ISOK),見下文Coco2D-X代碼(CCParticleSystem.cpp):未能通過Windows使用Cocos2D-X爲plist膨脹png
char *textureData = (char*)valueForKey("textureImageData", dictionary);
CCAssert(textureData, "");
int dataLen = strlen(textureData);
if(dataLen != 0)
{
// if it fails, try to get it from the base64-gzipped data
int decodeLen = base64Decode((unsigned char*)textureData, (unsigned int)dataLen, &buffer);
CCAssert(buffer != NULL, "CCParticleSystem: error decoding textureImageData");
CC_BREAK_IF(!buffer);
int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated);
CCAssert(deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");
CC_BREAK_IF(!deflated);
image = new CCImage();
bool isOK = image->initWithImageData(deflated, deflatedLen);
CCAssert(isOK, "CCParticleSystem: error init image with Data");
CC_BREAK_IF(!isOK);
m_pTexture = CCTextureCache::sharedTextureCache()->addUIImage(image, fullpath.c_str());
}
看來解碼成功通過,問題是在zlib的inflate()函數中,無法解壓png文件。
有什麼建議嗎?
你正在拋出一堆意味着不同事物的術語,所以你的代碼可能會有類似的困惑。 「unzip」與「ungzipping」不同,不同於png文件中的內容。你不能「解壓縮」一個PNG文件。 png文件包含zlib-wrapped數據。 zip,gzip和zlib是三種不同的格式,它們都是原始壓縮數據的不同包裝。您需要檢查ccInflateMemory期望的格式,並確保這就是您要給它的內容。 – 2012-07-06 16:02:21
對不起,沒有成爲專家,我想這就是爲什麼我在這裏問問題......正如我所說,這不是我的代碼,而是Cocos2d-x代碼,使用zlib。通過「解壓縮」,我的意思是「解壓縮」png文件。我不認爲這種格式有什麼問題,因爲它成功地擴大了其他一些嵌入式PNG。 – 2012-07-08 06:06:50