开发者

How can I use more than one sprite sheet? cocos2d/iPhone

开发者 https://www.devze.com 2023-01-08 22:04 出处:网络
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

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]开发者_JAVA技巧;
[[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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消