2

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.

GeneCode
  • 7,545
  • 8
  • 50
  • 85

1 Answers1

3

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.

YvesLeBorg
  • 9,070
  • 8
  • 35
  • 48
  • Hi. Yes, the files are in the target. And yes, I did enabled retina. Here is a screencapture of all 4 filenames. HERE: http://i.imgur.com/seAnufn.png – GeneCode Feb 10 '13 at 18:15
  • And the above plist screen shot is from the -hd file ? then this should work. – YvesLeBorg Feb 10 '13 at 18:24
  • I have "#define CC_RETINA_DISPLAY_FILENAME_SUFFIX @"-hd"" in ccConfig.h. As for suffix in plist.... I will double check and get back to u in 2 minutes. – GeneCode Feb 10 '13 at 18:25
  • Ok. Turns out the piece-hd.plist was having all pieceB1-hd.png, etc. Just remade the spritesheet after renaming all the hd assets (to without hd) and voila it works. God bless you, sir. Thanks so much! – GeneCode Feb 10 '13 at 18:30
  • 1
    my pleasure. Welcome to cocos2d ! once i got the hang of it, i think it is a great framework. – YvesLeBorg Feb 10 '13 at 18:31