views:

271

answers:

1

Hi all. I'm trying to use more than one sprite sheet because I can't fit them all on one and having two makes my ordering them easier (sprite sheet one sprites are in the back and have a lower zOrder). I'm currently doing:

spriteSheet1 = [[CCSpriteSheet spriteSheetWithFile:@"spriteSheet1.png" capacity:3] retain];
[[CCSpriteFrameCache sharedSpriteFrameCache]     addSpriteFramesWithFile:@"spriteSheet1.plist"];
[self addChild:spriteSheet1];

spriteSheet2 = [[CCSpriteSheet spriteSheetWithFile:@"spriteSheet2.png" capacity:4] retain];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"spriteSheet2.plist"];
[self addChild:spriteSheet2];

CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"sprite1.png"];

The last line crashes with the error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid spriteFrame for sprite' SIGABRT

Am I not allowed to cache more than one sprite sheet? If not, is there another efficient way to handle this?

A: 

If you create your spritesheets using Zwoptex, make sure you use the version of Zwoptex and cocos2d which support each other. Recently there have been major changes to Zwoptex and if you're using an older cocos2d version this might explain your crash.

In general the code you provided should work just fine, given that all the resource files haven been added to Xcode and are named properly. Keep in mind that the iOS devices are case-sensitive, if you try to load "spriteSheet1.plist" but the file is actually named "Spritesheet1.plist" it will also lead to errors (probably an assertion or crash).

GamingHorror