0
votes

Hello I am making a cocos2d side scroller. I need to use a sprite sheet for my game and when I do use it it gives me a SIGABRT error I used an exception breakpoint to see the exact line of code that is causing the problem and got this line:

NSAssert(spriteFrame!=nil, @"Invalid spriteFrame for sprite");

The output is:

2013-08-24 15:51:28.410 App[2171:a0b] sprite sheet name is 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)' not found 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)' not found 2013-08-24 15:51:28.422 App[2171:a0b] defaultPose = (null) 2013-08-24 15:51:28.422 App[2171:a0b] *** Assertion failure in -[CCSprite initWithSpriteFrame:],

Here is the code that is causing the problem and that is displaying this output:

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

I am using sprite sheets and a .plist file to make my game. The sprite sheet's .plist file looks like this: enter image description here

The .plist file I am using for game data looks like this: enter image description here

1
dump the contents of theDictionary, to figure out if it is as the image suggests it should be. Reading the logs and your code, it seems the PlayerProperties (theDictionary) is incomplete wrt your expected content.YvesLeBorg
ps: add an exception breakpoint in Xcode so you can see the exact line where things crash, and inspect variables.LearnCocos2D
2013-08-24 22:49:57.013 Zach's App[2488:a0b] key=AnimationBaseName value=thefinalcharacter 2013-08-24 22:49:57.013 Zach's App[2488:a0b] key=PlayerLocation value={301,384} 2013-08-24 22:49:57.014 Zach's App[2488:a0b] key=IsAnimated value=1 2013-08-24 22:49:57.015 Zach's App[2488:a0b] key=Gravity value=4 2013-08-24 22:49:57.015 Zach's App[2488:a0b] key=SpriteSheet value=characterssheet_poses 2013-08-24 22:49:57.016 Zach's App[2488:a0b] key=BruisedImage value=thefinalcharacter.png 2013-08-24 22:49:57.017 Zach's App[2488:a0b] key=FramesToAnimate value=4PoKoBros
To add to the comment directly above, this is the new output. I want the BaseImage to be changedcharacters.png and I want the BruisedImage to be changedcharacters2.png. No matter what I do it will not change. P.S. I iterated through theDictionary.PoKoBros

1 Answers

0
votes

You have a dictionary in a dictionary situation.

Your theDictionary object points to the root of the plist. First problem is: since you have 2 different plists you can't use the same dictionary object to read information from both plists. Without seeing how you initialize theDictionary I can't tell but unless you merged the contents of both plists only one of the two plist's information will be in it.

Next if you want to get the PlayerProperties (or frames) dictionary, you'd have to do something like this (assuming theDictionary represents the game data dictionary):

NSDictionary* characters = [theDictionary objectForKey:@"Characters"];
NSDictionary* player = [characters objectForKey:@"Player"];
NSDictionary* properties = [player objectForKey:@"PlayerProperties"];
NSString* spritesheet = [properties objectForKey:@"SpriteSheet"];

Or somewhat more convenient with KVC:

NSString* spritesheet = 
    [theDictionary objectForKey:@"Characters.Player.PlayerProperties.SpriteSheet"];