我目前正在为新的V3.4引擎修复一个旧的Cocos iPhone Xcode项目。它过去工作得非常好,但是我找到了这一行代码:
CCParticleSystem *fire = [CCParticleSystemQuad particleWithFile:@"fire.plist"];CCParticleSystemQuad已被删除,因此我将其替换为"CCParticleSystem":
CCParticleSystem *fire = [CCParticleSystem particleWithFile:@"fire.plist"];它不断地使用以下错误消息攻击这一行代码:
- cocos2d: Couldn't find file:user_particle30956.png
- *** Assertion failure in -[CCTextureCache addCGImage:forKey:], /Users/.../Source/libs/cocos2d-iphone/cocos2d/CCTextureCache.m:370
- *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'该图像不存在,实际上作为纹理图像数据嵌入到plist文件中。我知道,在Cocos V 2中,它会自动创建和存储这个纹理图像数据,作为一个带有名称的图像文件。我怎样才能为V3工作?
我不知道你需要多少关于plist文件的信息。这是一长串粒子系统配置(角度、持续时间、发射器类型等)的信息:
<key>textureFileName</key>
<string>user_particle30956.png</string>
<key>textureImageData</key>
<string>eJztnQecXWURxXdDgCCggBQLuisqKlbslcSCBcEC9pa1996wkbUr9q5...</string>谢谢各位。
发布于 2016-01-05 11:53:44
我也遇到过同样的问题。在粒子设计文档中,嵌入的纹理显然是TIFF,而不是Cocos2D所期望的PNG。
我不明白这一点,因为它过去在Cocos2D v2.2中运行得很好。
在v3.4.x中,我所做的是更改粒子设计器项目,将纹理导出为一个文件,然后将该文件添加到Xcode项目中,以便粒子系统以艰难的方式加载它。
您可以查看v2.2代码,看看它做了什么。也许这段代码可以带到v3.4.x
在查看了v2.2代码之后,从嵌入式图像中获取二进制数据并将其转换为纹理的机制使用了UIImage,而不是一些特定于PNG/JPEG的代码。
// Cocos2d v2.2
//
#ifdef __CC_PLATFORM_IOS
UIImage *image = [[UIImage alloc] initWithData:data];
#elif defined(__CC_PLATFORM_MAC)
NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithData:data];
#endifv3.x代码这样做(对于iOS和Android):
// Cocos2D v3.x
//
BOOL png = [[[dictionary valueForKey:@"textureFileName"] lowercaseString] hasSuffix:@".png"];
CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
CGImageRef image = (png) ? CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault) : CGImageCreateWithJPEGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault) ;我强烈怀疑以下内容可能有效(尽管我自己还没有测试过):
#if __CC_PLATFORM_IOS
UIImage *image = [[UIImage alloc] initWithData:data];
[self setTexture: [ [CCTextureCache sharedTextureCache] addCGImage:[image CGImage] forKey:textureName]];
#elif __CC_PLATFORM_ANDROID
BOOL png = [[[dictionary valueForKey:@"textureFileName"] lowercaseString] hasSuffix:@".png"];
CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
CGImageRef image = (png) ? CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault) : CGImageCreateWithJPEGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault) ;
[self setTexture: [ [CCTextureCache sharedTextureCache] addCGImage:image forKey:textureName]];
CGDataProviderRelease(imgDataProvider);
CGImageRelease(image);
#elif __CC_PLATFORM_MAC
NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithData:data];
[self setTexture: [ [CCTextureCache sharedTextureCache] addCGImage:[image CGImage] forKey:textureName]];
#endif我尝试在这里允许使用Android,但是如果嵌入的纹理确实是TIFF,那么它将如何工作,Android桥接库也希望PNG/JPEG。
https://stackoverflow.com/questions/32161562
复制相似问题