0

This problem is from the makegameswith.us website and their Peeved Penguin project. I am attempting to modify it to read the level data from a plist rather than GameLayer.mm, the first sprite data reads in as expected the second pass through the while loop returns (Null) for the sprite name. I've looked at the plist, both sprites should have the same file name "tallblock".

Here is the relevant snippet of code:

CCLOG(@"About to load level data.");

    // Load Level Data and Draw Level Sprits
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Level1" ofType:@"plist"];
    NSDictionary *level = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *levelBlocks = [level objectForKey:@"Blocks"]; // Capitalization matters

    NSEnumerator *enumerator = [levelBlocks objectEnumerator];
    id object;
    NSString *spriteName;
    NSString *spriteFile;
    NSNumber *xPos;
    NSNumber *yPos;

    // One of my sprite names is invalid...
    while (object = [enumerator nextObject])
    {
        spriteName = [object objectForKey: @"spriteName"];
        spriteFile = [spriteName stringByAppendingString:@".png"];

        CCLOG(@"Sprite File is : %@", spriteFile); // Second sprite doesn't load is null...
        sprite = [CCSprite spriteWithFile: spriteFile];
        xPos = [object objectForKey: @"x"];
        yPos = [object objectForKey: @"y"];
        sprite.position = CGPointMake([xPos floatValue], [yPos floatValue]);
        [blocks addObject:sprite];
        [self addChild: sprite
                     z: 7];
    }

    CCLOG(@"Finished Loading Level Data.");

I put this problem/issue in the official forum, but I've received no advice. I've stepped through the code many times in the debugger and I don't understand why it finds tallblocks on pass one but not on pass two.

I took a screenshot of the plist file. Any ideas why the code fails on the second sprite?

Plist Screen Shot

2 Answers 2

1

There's an R missing in Item 1's spriteName...

1
  • Damnit! I looked at the name of the file not the name of the key. I spent a lot of time on this and it is a stupid 'r'...
    – Muskie
    Apr 20, 2013 at 0:01
0

your second array entry has key 'spiteName' as opposed to 'spriteName'

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.