我的应用程序从URL获取一些资源,特别是.pvr.ccz
,并将它们保存在Documents
目录中。
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
...
[responseObject writeToFile:[documentsDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", <file_name>, @"pvr.ccz"]] options:NSAtomicWrite error:nil];
之后使用.plist
和.pvr.ccz
创建精灵。项目中已有的属性列表中指定的.png
图像的列表。
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"<property_list_name>.plist"];
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"<file_name>.png"]];
这将被警告-[CCFileUtils fullPathFromRelativePath:resolutionType:] : cocos2d: Warning: File not found: <file_name>.pvr.ccz
有没有办法让 Cocos2D 可以从保存在特定文件夹中的 URL 中搜索资源?或者有没有办法将 URL 中的资源保存在 Cocos2D 可以找到它们的地方?
,如果您指定 coco 的完整路径,它会在那里显示。因此
NSString*fqn = [documentsDirectoryPath stringByAppendingPathComponent@"<property_list_name>.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:fqn];
没有尝试过这个,但它应该有效。
编辑:假设.plist在项目中,但.pvr.ccz在文档字典中。进一步假设您的纹理称为"downloaded-hd.pvr.ccz",该项目为设备启用高清,以下示例应找到您的文件:
NSString*textureFileName=@"downloaded-hd.pvr.ccz";
NSString*fqn =
[documentsDirectoryPath stringByAppendingPathComponent:textureFileName];
[[CCSpriteFrameCache sharedSpriteFrameCache]
addSpriteFramesWithFile:@"<property_list_name>.plist"
textureFileName:fqn];
我认为 -HD 将被静默正确处理。