您好我正在制作一个cocos2d侧卷轴。我需要为我的游戏使用精灵表,当我使用它时,它给我一个SIGABRT错误我使用异常断点来查看导致问题的确切代码行并得到这一行:
NSAssert(spriteFrame!=nil, @"Invalid spriteFrame for sprite");
输出结果为:
2013-08-24 15:51:28.410 App [2171:a0b]精灵表名称是characterssheet_poses 2013-08-24 15:51:28.419 App [2171:a0b] bruisedImage =(null) 2013-08-24 15:51:28.420 App [2171:a0b] cocos2d:CCSpriteFrameCache:未找到Frame'(null)' 2013-08-24 15:51:28.420 App [2171:a0b] bruisedPose =(null) 2013-08-24 15:51:28.421 App [2171:a0b] defaultImage =(null) 2013-08-24 15:51:28.421 App [2171:a0b] cocos2d:CCSpriteFrameCache:未找到Frame'(null)' 2013-08-24 15:51:28.422 App [2171:a0b] defaultPose =(null) 2013-08-24 15:51:28.422 App [2171:a0b] ***断言失败 - [CCSprite initWithSpriteFrame:],
以下是导致问题并显示此输出的代码:
NSString* spriteSheetName = [theDictionary objectForKey:@"SpriteSheet"];
CCLOG(@"sprite sheet name is %@", spriteSheetName);
NSString* plistName = [NSString stringWithFormat:@"%@.plist", spriteSheetName ];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:plistName ];
NSString* bruisedImage = [theDictionary objectForKey:@"BruisedPose"];
CCLOG(@"bruisedImage = %@",bruisedImage);
bruisedPose = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:bruisedImage];
CCLOG(@"bruisedPose = %@",bruisedPose);
NSString* defaultImage = [theDictionary objectForKey:@"BasePose"];
CCLOG(@"defaultImage = %@",defaultImage);
defaultPose = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:defaultImage];
CCLOG(@"defaultPose = %@",defaultPose);
我正在使用精灵表和.plist文件制作我的游戏。精灵表的.plist文件如下所示:
我用于游戏数据的.plist文件如下所示:
答案 0 :(得分:0)
你在字典情况下有一本字典。
您的theDictionary
对象指向plist的根。第一个问题是:由于您有2个不同的plist,因此无法使用相同的字典对象从两个plist中读取信息。没有看到你如何初始化theDictionary
我无法分辨,但除非你合并两个plist的内容,否则只有其中一个plist信息中的一个。
接下来,如果你想获得PlayerProperties(或框架)字典,你必须做这样的事情(假设theDictionary代表游戏数据字典):
NSDictionary* characters = [theDictionary objectForKey:@"Characters"];
NSDictionary* player = [characters objectForKey:@"Player"];
NSDictionary* properties = [player objectForKey:@"PlayerProperties"];
NSString* spritesheet = [properties objectForKey:@"SpriteSheet"];
或者对KVC来说更方便:
NSString* spritesheet =
[theDictionary objectForKey:@"Characters.Player.PlayerProperties.SpriteSheet"];