0

Using Texture Packer, I am placing my iPhone5 background images in a pvr.ccz file and saving the output files in the Resources folder of my cocos2d project. When I attempt to load the pvr.ccz file, I get the following series of errors:

cocos2d: Filename(StoreMenuBackground_iPhone5-hd.pvr.ccz) contains -hd suffix.
cocos2d: CCFileUtils: Warning HD file not found: StoreMenuBackground_iPhone5-hd.pvr.ccz
cocos2d: Error loading CCZ compressed file

and then the code crashes with EXC_BAD_ACCESS in a method called ccInflateCCZFile (in the cocos2D file ZipUtils.m). My line of code that I am executing is:

backgroundBgNode = [CCSpriteBatchNode batchNodeWithFile:@"StoreMenuBackground_iPhone5-hd.pvr.ccz"];

Now the strange thing is that if I recreate the pvr.ccz file in Texture Packer without the -hd extension on either the pvr.ccz or the background png image that I am trying to load, and then place the resultant output files in the Resources folder and rerun the code, then no error is detected. If I then delete this pvr.ccz and associated .plist file (the one without the -hd extension) from the Resources folder, everything is fine. Being skeptical, I then did a Clean and a new Build, and it is still working.

Why am I getting this error to start with? And why does it go away when I do the steps outlined above. Can I trust that the end result is valid?

I am using Cocos2d V1.0. I have tried this on multiple background images, and they all behave the same. I also do not have this problem for iPad or iPad-hd.

JeffB6688
  • 3,782
  • 5
  • 38
  • 58

1 Answers1

1

Because cocos2d searches for the -hd suffixed files automatically on Retina devices. You're not supposed to use filenames using any of the -hd/-ipad#/-ipadhd/-wide/-widehd suffixes directly.

You can tweak the suffix mappings with CCFileUtils, though that's very limited in cocos2d-iphone v1.0.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Just to be clear, are you saying that I shouldn't be using the -hd suffix on the .png file, or are you saying I shouldn't be using the -hd suffix on the .pvr.ccz file? If I don't use it on either of them, then it doesn't work either. What tweaking of the suffix mapping are you referring to? As far as I can see, Cocos2d V1 doesn't have the capability for [sharedFileUtils setiPadSuffix:@"-ipad"]; Is there another way to do this? – JeffB6688 Oct 17 '13 at 22:48
  • You shouldn't be referencing the suffixed versions of a file when loading it by passing a string like this @"StoreMenuBackground_iPhone5-hd.pvr.ccz" - instead you just use the base version of the file and let cocos2d decide which (if any) suffix version it should use: @"StoreMenuBackground_iPhone5.pvr.ccz" PS: maybe you should at least upgrade to v1.1, given this kind of problem sounds like an early stage development issue then that shouldn't be too much trouble (even better if you can use v2.1). v1.0 lacks proper iPad Retina support. – CodeSmile Oct 17 '13 at 22:52
  • I did as you suggested (i.e. changed my code to: backgroundBgNode = [CCSpriteBatchNode batchNodeWithFile:@"StoreMenuBackground_iPhone5.pvr.ccz"];), but I still get the last two errors I mentioned in the problem statement. Specifically I get: cocos2d: CCFileUtils: Warning HD file not found: StoreMenuBackground_iPhone5-hd.pvr.ccz and I get: cocos2d: Error loading CCZ compressed file. This is followed with the EXC_BAD_ACCESS I mentioned in the problem statement. Can you see anything else I may be doing wrong? I am also seeing this with other devices contrary to what I said. – JeffB6688 Oct 18 '13 at 14:35
  • Note that when it enters ccInflateCCZFile, the path does not contain the -hd suffix (which does not exist in my Resource folder). Then it calls ccLoadFileIntoMemory. This returns with a filelen = -1. That causes the 2nd error message and ultimately the EXC_BAD_ACCESS. – JeffB6688 Oct 18 '13 at 14:43
  • I also want to point out that the TexturePacker files that I created in my Resource folder are: StoreMenuBackground_iPhone5-hd.pvr.ccz and StoreMenuBackground_iPhone5-hd.plist. The image in the pvr.ccz file and pointed to in the .plist file is an image with a -hd suffix. If this is still not correct, please let me know. – JeffB6688 Oct 18 '13 at 14:49
  • 1
    the image names (aka sprite frame names) inside the texture atlas should not have any suffix like -hd. You'd have xxx.plist + xxx.png and for HD xxx-hd.plist and xxx-hd.png but inside both atlases the images should have the same names, like "example.png" in both -hd and non-hd atlases. – CodeSmile Oct 18 '13 at 15:42
  • Ok, I finally get it. If I have an hd retina device, use the hd suffix on the filenames for the pvr and plist files (e.g. xxx-hd.pvr.ccz and xxx-hd.plist), but DO NOT put the hd suffix on the image names inside the texture atlas. ALSO, in the code, only reference the pvr.ccz, plist, and sprite image files without the hd suffix (regardless of the device) because cocos2d will automatically figure out whether to use xxx.pvr.ccz or xxx-hd.pvr.ccz and it will automatically figure out whether to use xxx.plist or xxx-hd.plist. Thanks for your patience. – JeffB6688 Oct 24 '13 at 19:09