1

我正在使用 Mac 创建的 plist 文件运行 Coco2D-X 的particleWithFile() 函数。使用“textureImageData”键将图像数据嵌入到 plist 文件中。在 Mac 上它可以正常工作,但在 Windows 上它会失败,在 CCAssert(isOK) 上,请参阅下面的 Coco2D-X 代码 (CCParticleSystem.cpp):

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文件。

有什么建议么?

4

2 回答 2

0

好的,我发现了问题。

显然我的资源不是 png 文件,而是 tiff 文件。所以 Inflate() 返回了一个正确的缓冲区(一个 tiff 文件 - 对我来说看起来太长了,所以我怀疑它是错误的),但是 initWithImageData() 未能创建图像,因为 tiff 在 windows 上不受 Cocos2d-x 支持。

于 2012-07-08T13:39:07.623 回答
0

我遇到问题是因为我将 CC_USE_TIFF 设置为 0。

在我将 CC_USE_TIFF 恢复为 1 后,问题解决了。

于 2015-07-25T07:12:09.880 回答