这个问题来自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文件的截图。任何想法为什么代码在第二个精灵失败?
该死!我查看了文件的名称,而不是密钥的名称。我在这花了很多时间,这是一个愚蠢的'r'... – Muskie 2013-04-20 00:01:17