2013-04-19 48 views
0

這個問題來自makegameswith.us網站和他們的Peeved Penguin項目。我試圖修改它來讀取plist而不是GameLayer.mm的級別數據,第一個精靈數據按預期讀入第二次通過while循環返回(Null)精靈名稱。我看過plist,這兩個sprites應該有相同的文件名「tallblock」。從plist讀取數據時爲什麼是第二個值(空)?

這裏是代碼中的相關片段:

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."); 

我把這個問題/問題in the official forum,但我沒有收到任何意見。我已經在調試器中多次瀏覽過代碼,我不明白爲什麼它會在第一次傳球時找到高擋,而不是第二傳。

我截取了plist文件的截圖。任何想法爲什麼代碼在第二個精靈失敗?

Plist Screen Shot

回答

1

還有的R缺少項1的spriteName ...

+0

該死!我查看了文件的名稱,而不是密鑰的名稱。我在這花了很多時間,這是一個愚蠢的'r'... – Muskie 2013-04-20 00:01:17

0

你的第二個數組項具有關鍵 'spiteName' 而不是 'spriteName'