Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am currently doing this Cocos2d tutorial: http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d

...and get the following error messages:

2011-12-30 16:36:28.536 AnimBear[11273:10a03] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2011-12-30 16:36:28.537 AnimBear[11273:10a03] cocos2d: Couldn't add image:AnimBear_default.png.ccz in CCTextureCache
2011-12-30 16:36:28.537 AnimBear[11273:10a03] cocos2d: CCSpriteFrameCache: couldn't load texture file. File not found: AnimBear_default.png.ccz
2011-12-30 16:36:28.538 AnimBear[11273:10a03] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2011-12-30 16:36:28.538 AnimBear[11273:10a03] cocos2d: Couldn't add image:AnimBear_default.png.ccz in CCTextureCache
2011-12-30 16:36:28.539 AnimBear[11273:10a03] cocos2d: CCSpriteFrameCache: couldn't load texture file. File not found: AnimBear_default.png.ccz
2011-12-30 16:36:28.540 AnimBear[11273:10a03] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2011-12-30 16:36:28.540 AnimBear[11273:10a03] cocos2d: Couldn't add image:AnimBear_default.png.ccz in CCTextureCache
2011-12-30 16:36:28.541 AnimBear[11273:10a03] cocos2d: CCSpriteFrameCa[Switching to process 11273 thread 0x1410b]
[Switching to process 11273 thread 0x10a03]
che: Frame 'bear1.png' not found
2011-12-30 16:36:28.598 AnimBear[11273:10a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x17e4052 0x1975d0a 0x17d136e 0x17d2220 0xc1997 0x3fcf1 0xc16dd 0xc0d7c 0x828b0e 0x8298a6 0x838743 0x8391f8 0x82caa9 0x2798fa9 0x17b81c5 0x171d022 0x171b90a 0x171adb4 0x171accb 0x8292a7 0x82aa9b 0xc085f 0x2135)
terminate called throwing an exceptionsharedlibrary apply-load-rules all

I have the following files in the Resource folder:

  • AnimBear_default.png.ccz
  • AnimBear_default.plist

The texture consists of eight(8) bears named Bear1.png - Bear8.png. I have bought and done the texture in Zwoptex, latest version.

The code looks like:

-(id) init {

if((self = [super init])) {

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"AnimBear_default.plist" textureFile:@"AnimBear_default.png.ccz"];
    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"AnimBear_default.png.ccz"];
    [self addChild:spriteSheet];

    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for (int i = 1; i <= 8 ; ++i) {
        [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"bear%d.png", i]]];
    }

    CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];

    CGSize winSize = [CCDirector sharedDirector].winSize;
    self.bear = [CCSprite spriteWithSpriteFrameName:@"bear1.png"];        
    _bear.position = ccp(winSize.width/2, winSize.height/2);
    self.walkAction = [CCRepeatForever actionWithAction:
                       [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
    [_bear runAction:_walkAction];
    [spriteSheet addChild:_bear];


}
return self;

}

I am completely new to Cocos2d and have been trying to search the web and tried different things but with no success :-(

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Not sure if that's the issue, but you have an error in your init method. You should put all your initialization within the if((self = [super init])) { block.

So remove the first two lines from your init block (as they seem to be redudant anyway):

-(id) init 
{
    if((self = [super init])) {
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"AnimBear_default.plist" textureFile:@"AnimBear_default.png.ccz"];
        CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"AnimBear_default.png.ccz"];
        [self addChild:spriteSheet];

        NSMutableArray *walkAnimFrames = [NSMutableArray array];
        for (int i = 1; i <= 8 ; ++i) {
            [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"bear%d.png", i]]];
        }

        CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];

        CGSize winSize = [CCDirector sharedDirector].winSize;
        self.bear = [CCSprite spriteWithSpriteFrameName:@"bear1.png"];        
        _bear.position = ccp(winSize.width/2, winSize.height/2);
        self.walkAction = [CCRepeatForever actionWithAction:
                           [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
        [_bear runAction:_walkAction];
        [spriteSheet addChild:_bear];
    }
    return self;
}
share|improve this answer
    
oh my fault i used those lines when i tested, i removed it now. tests show same result, obvious i do not load the sprites. –  PeterK Dec 30 '11 at 20:18
    
@PeterK Did you add the files to the XCode project (using "Add files")? Copying them to the Resource folder alone is not enough, you'll have to add them to the "Resource" group in XCode as well. –  bummzack Dec 30 '11 at 20:23
    
yes i did. Actually i think i solved it as i found out how to save the sprite sheet without compression (.ccz) and load that i got it to work. –  PeterK Dec 30 '11 at 20:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.