Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top