Discussion in 'iOS Programming' started by esierr1, Jul 30, 2012.

  1. esierr1 macrumors newbie

    Jul 30, 2012
    Hey guys, I have a .plist file with .png files in it.

    I have some questions regarding this:

    1) Is there a way to extract those .png files from the .plist file? Or a program that does that?
    2) Can I edit the resolution of the .png files that are on the .plist file?

    I need to update the images for the iPad 3 retina display.

    Any advice is more than welcomed. Thank you!
  2. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia
    A plist file can't contain .png files, or images of any kind. (At least not directly.)

    Property list files can only contain a very small list of object types. (NSString, NSData, NSDate, NSNumber, NSArray, or NSDictionary objects.)

    It is possible to convert images to NSData and store that in a plist.

    It's usually better to save filenames or pathnames into a property list, and then save the images to those filenames.

    Property lists are frequently a container object like an array with a group of other objects stored inside it. You might have an array of strings containing paths to images.

    You can't "edit the resolution" of images. You can load the contents of the plist, convert the array object to a mutable array, replace the images with higher resolution versions, and save the array back to your property list file. Exactly how you would do that depends on the contents and format of your property list file.

    If you are trying to create higher resolution images for Retina displays, there is no point in taking your standard resolution images and making them bigger. At best, the result will be files that are 4 times as large (2x in height and 2x in width) with no increase in sharpness. More likely you'll create images that are 4 times as large and look worse than what you started with. You need to either have an artist create new images at 2x the resolution, or recreate the raster (pixel) images from a vector format like Illustrator or an EPS file.
  3. esierr1 thread starter macrumors newbie

    Jul 30, 2012
    Thank you for your advice Duncan. What I did was the following:

    -I created new images for the new iPad retina display.
    -Created the sprite sheets with Zwoptex and generated the .plist file.

    The problem is that I am having issues linking these sprite sheets to my iOS game. I loaded the .plist and .png files created on Zwoptex to Xcode, but the changes are not being recognized. I don't know why this is happening. By the way, the game was created with cocos.

  4. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia

    You are going to have to post a LOT more details if anybody online is going to be able to help you sort it out. What do you mean "The changes are not being recognized? You can't see the plist and png files in your Xcode project? You can see the files but they are older versions that don't show recent changes? You can see the files in your Xcode project, but they are not available in your program at runtime?

    How did you add the files? What is Zwoptex? Is that a utility that works with cocos2d? What does it do?
  5. esierr1 thread starter macrumors newbie

    Jul 30, 2012
    Zwoptex is a utility application to create sprite sheets and it also creates .plist files.

    I manually added the .plist and the related .png files to the xcode project. All these files do show up on the Project Navigator, so I do see them. I proceeded to update the AppDelegate.m on the project using the following code:

    // Removes the startup flicker
    	[self removeStartupFlicker];
        // Load the sprite files
        if ( [GameUtils sharedUtils].deviceType == kDeviceIPad ) {
            [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Images.plist"];
            [CCSpriteBatchNode batchNodeWithFile:@"Images.png"];
            [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Images1.plist"];
            [CCSpriteBatchNode batchNodeWithFile:@"Images1.png"];
            [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Images2.plist"];
            [CCSpriteBatchNode batchNodeWithFile:@"Images2.png"];
            [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Images@2x~ipad.plist"];
            [CCSpriteBatchNode batchNodeWithFile:@"Images@2x~ipad.png"];
            [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Images1@2x~ipad.plist"];
            [CCSpriteBatchNode batchNodeWithFile:@"Images1@2x~ipad.png"];
            [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Images2@2x~ipad.plist"];
            [CCSpriteBatchNode batchNodeWithFile:@"Images2@2x~ipad.png"];
    ***The @2x~ipad files were the recently added to the xcode project.

    Once I save and I run my project, it doesn't recognize the newly added files.

    I don't know what is going on. Please help me.

  6. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Did you make sure to copy the files into the project (i.e. check the box for "Copy items into destination group's folder" when adding them)?
  7. esierr1 thread starter macrumors newbie

    Jul 30, 2012
    Yes, I checked that box. After I added the files, then I updated the AppDelegate.m. I don't know what I am doing wrong.
  8. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia

    It might be that the @2x~ipad files will only be used if you also have a ~ipad (non @2x) version of the file. In fact, it's pretty likely.

    Why would you add Retina iPad art but not non-retina iPad art? The huge image sizes for Retina iPad will choke the original iPad. It has the lowest amount of memory relative to it's screen size of any recent iOS device, and your apps will run out of memory and crash if you try and make it display retina images.
  9. esierr1 thread starter macrumors newbie

    Jul 30, 2012
    images.png is the non-retina iPad art, so both artworks were are added to Xcode. The problem is the retina display art, I can't seem to make it work.

    I apologize, I am new to all this. Any suggestions or ideas are more than welcome!
  10. chown33 macrumors 604

    Aug 9, 2009
    You need to narrow down "I can't seem to make it work".

    Break it down into a series of individual questions, determine the answer to each question, then narrow down the cause. This is a fundamental debugging skill, so get used to doing it.

    Does it not work because the image files don't exist?
    Or is it because the image files are the wrong format?
    Or is it something else?

    There are a limited number of possible questions, and you should be able to break it down into a tree of yes/no questions. If the answer to one question is yes, that will result in one kind of follow-up question. If the answer is no, it will result in a different follow-up question.

    I recommend that you actually write the questions down, make sure each one can be answered with yes or no, then write down the subsequent question in each branch. Having them written down gives you a written plan of action, where you can cross things off as you discover answers. It also lets you refer back to questions you think you've answered, in case you run into logical problems (e.g. something turns out not to be strictly yes/no, or the answers aren't mutually exclusive and collectively exhaustive).

    To determine if the files exist or not, use NSFileManager. You can also use NSBundle to make pathnames, which you then pass to NSFileManager to determine existence. And be sure to actually look at the pathnames (e.g. NSLog it), so you know what NSFileManager is checking the existence of.

    Once you've determined existence, you take a different branch depending on the outcome. If the files exist, determine whether they're the correct format or not. If the files don't exist, go to your build process and determine why they're not being copied.

    If the files aren't being copied, you have to determine if they're not being copied at all, or whether they're being copied but not in the place you expect them to be.

    You can use NSFileManager to tell you every file in your app's bundle directory, so maybe you should do that first to see if the image files are anywhere in the bundle. If they exist but in the wrong place, at least you know what the problem is. And if they don't exist at all, then you still know what the problem is.

    You'll probably have to dig into the cocos2d docs, to learn where the sprite-files are loaded from. It could be the problem is as simple as it's looking somewhere you didn't expect it to.

    You'll also have to read the reference docs for NSBundle and NSFileManager, which is another fundamental debugging skill.
  11. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia
    You said "]images.png is the non-retina iPad art"
    No, its not.

    The system will only look for ~iPad@2x retina versions of artwork if it sees an ~iPad non-retina version. If your base artwork is "foo.png", and there is no "foo~iPad.png", it will not look for "foo~iPad@2x.png.

    That is almost certainly your problem.

Share This Page