xcodecocos2d-iphoneccspriteccspritebatchnode

Cocos2d Spritesheet not loading (spriteWithSpriteFrameName)


I am a noob in cocos2d and learning as I develop. I read in cocos2d docs, and also from Ray Wenderlich tutorials, I tried to create spritesheet, but so far has been unable to load ANY of my sprites from the spritesheet I created. Sprites are showing fine when I just use plain CCSprite spriteFromFile: directly. Anyway, I created the spritesheet in Zwoptex. I chose png file and Coordinates as Cocos2d .plist. Drag and drop both files (png and plist) into my project Resources group, and wrote the following code in init method.

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"piece.plist"];
CCSpriteBatchNode *pieceSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"piece.png"];
[self addChild:pieceSpriteSheet];

CCSprite *block = [CCSprite spriteWithSpriteFrameName:@"pieceB1.png"];

I have checked the names of files, the capitalization, and even remade the spritesheet many times, but still cocos2d cannot load pieceB1.png, eventhough it is there in plist and png. Here's the screenshot of the plist file:

enter image description here

Error I got:

2013-02-11 01:33:04.808 sequence[5787:12203] cocos2d: CCSpriteFrameCache: Trying to use file 'piece.png' as texture 
2013-02-11 01:33:04.815 sequence[5787:12203] cocos2d: CCSpriteFrameCache: Frame 'pieceB1.png' not found 
2013-02-11 01:33:04.818 sequence[5787:12203] cocos2d: Frame interval: 1 
2013-02-11 01:33:04.822 sequence[5787:12203] Application windows are expected to have a root view controller at the end of application launch 
2013-02-11 01:33:04.822 sequence[5787:12203] cocos2d: surface size: 640x960 
2013-02-11 01:33:07.044 sequence[5787:12203] cocos2d: CCSpriteFrameCache: Frame 'pieceG1.png' not found 
2013-02-11 01:33:07.045 sequence[5787:12203] *** Assertion failure in +[CCSprite spriteWithSpriteFrameName:]

Thanks.


Solution

  • Did you verify that your files are in the target ? Also, is your game enabling HD ? if yes, both your plist and png file should be suffixed appropriately. The "addSpriteFramesWithFile" call fails silently if the file is not found.