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 testing (and learning) animation in Cocos2d using a series of .png's called "splash-x.png". I am getting error and at the first sight i thought it was easy to solve but it turned out that i cannot figure out where the problem is. I have tried breakpoints etc. but can still not fix it.

Would any nice person help me to solve this it would be highly appreciated.

Using the following code:

-(id) init {
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {

    // Add background
    CGSize winSize = [CCDirector sharedDirector].winSize;
    CCSprite *bg = [CCSprite spriteWithFile:@"background.png"];
    bg.position = ccp(winSize.width/2, winSize.height/2);
    [self addChild:bg z:-2];

    // Add foreground
    CCSprite *slang = [CCSprite spriteWithFile:@"slangen.png"];
    slang.anchorPoint = ccp(0.5, 1);
    slang.position = ccp(250, 300);
    [self addChild:slang z:1];

    CCSprite *slangslutet = [CCSprite spriteWithFile:@"slanslut.png"];
    slangslutet.anchorPoint = ccp(0, 1);
    slangslutet.position = ccp(390,120);
    [self addChild:slangslutet z:-1];
    CCRotateBy* rotateBy = [CCRotateBy actionWithDuration:1 angle:-180];
    [slangslutet runAction:rotateBy];


    //splash animation
    NSMutableArray *splashAnimFrames = [NSMutableArray array];
    for (int i = 1; i <= 6 ; ++i) {
        NSLog(@">>>>  %i",i);
        [splashAnimFrames addObject:[NSString stringWithFormat:@"splash-%d.png", i]];
        NSLog(@"splash-%d.png", i);
    }

    NSLog(@"%@",splashAnimFrames); 

    CCAnimation *splashAnim = [CCAnimation animationWithFrames:splashAnimFrames delay:0.1f];

    self.splashing = [CCSprite spriteWithFile:@"splash-1.png"];        
    _splashing.position = ccp(310,330);
    self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:splashAnim restoreOriginalFrame:NO]];
    [_splashing runAction:_walkAction];
    [self addChild:_splashing];

 }
return self;
}

I get the following error messages:

2012-02-02 00:10:38.350 slangtest[8224:10a03] >>>>  1
2012-02-02 00:10:38.350 slangtest[8224:10a03] splash-1.png
2012-02-02 00:10:38.351 slangtest[8224:10a03] >>>>  2
2012-02-02 00:10:38.351 slangtest[8224:10a03] splash-2.png
2012-02-02 00:10:38.351 slangtest[8224:10a03] >>>>  3
2012-02-02 00:10:38.352 slangtest[8224:10a03] splash-3.png
2012-02-02 00:10:38.352 slangtest[8224:10a03] >>>>  4
2012-02-02 00:10:38.353 slangtest[8224:10a03] splash-4.png
2012-02-02 00:10:38.353 slangtest[8224:10a03] >>>>  5
2012-02-02 00:10:38.354 slangtest[8224:10a03] splash-5.png
2012-02-02 00:10:38.354 slangtest[8224:10a03] >>>>  6
2012-02-02 00:10:38.354 slangtest[8224:10a03] splash-6.png
2012-02-02 00:10:38.355 slangtest[8224:10a03] (
"splash-1.png",
"splash-2.png",
"splash-3.png",
"splash-4.png",
"splash-5.png",
"splash-6.png"
)
2012-02-02 00:10:38.356 slangtest[8224:10a03] cocos2d: Frame interval: 1
2012-02-02 00:10:38.507 slangtest[8224:10a03] -[__NSCFString rect]: unrecognized selector sent to instance 0x744f330
2012-02-02 00:10:38.508 slangtest[8224:10a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString rect]: unrecognized selector sent to instance 0x744f330'
*** First throw call stack:
(0x17e4052 0x1975d0a 0x17e5ced 0x174af00 0x17e51e2 0x6acb3 0x18699 0x104ec 0x2ac6 0x1e08d 0x64906 0x8da1f 0x9000a 0x2a92db 0x2a91af 0x17b8966 0x17b8407 0x171b7c0 0x171adb4 0x171accb 0x2797879 0x279793e 0x82aa9b 0xc086f 0x2145)
terminate called throwing an exceptionsharedlibrary apply-load-rules all

SOLUTION

Thanks to Robin i figured out the mistake, a BIG thank you. Now i know how this thing works, i think :-)

I also converted the .png's into TexturePacker format. Here is the solution:

-(id) init {
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {

    // Add background
    CGSize winSize = [CCDirector sharedDirector].winSize;
    CCSprite *bg = [CCSprite spriteWithFile:@"background.png"];
    bg.position = ccp(winSize.width/2, winSize.height/2);
    [self addChild:bg z:-2];

    // Add foreground
    CCSprite *slang = [CCSprite spriteWithFile:@"slangen.png"];
    slang.anchorPoint = ccp(0.5, 1);
    slang.position = ccp(250, 300);
    [self addChild:slang z:1];

    CCSprite *slangslutet = [CCSprite spriteWithFile:@"slanslut.png"];
    slangslutet.anchorPoint = ccp(0, 1);
    slangslutet.position = ccp(390,120);
    [self addChild:slangslutet z:-1];

    CCRotateBy* rotateBy = [CCRotateBy actionWithDuration:1 angle:-180];
    [slangslutet runAction:rotateBy];





    //Add splash animation

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"splash.plist" textureFile:@"splash.pvr.ccz"];
    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"splash.pvr.ccz"];
    [self addChild:spriteSheet];
    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for (int i = 1; i <= 6 ; ++i) {
        [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"splash-%d.png", i]]];
    }

    CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
    self.splashing = [CCSprite spriteWithSpriteFrameName:@"splash-1.png"];
    _splashing.anchorPoint = ccp(0, 0);
    _splashing.position = ccp(310,330); //winSize.width/2, winSize.height/2);
    self.walkAction = [CCRepeatForever actionWithAction:
                       [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
    [_splashing runAction:_walkAction];
    [spriteSheet addChild:_splashing];


}
return self;
}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

The problem is in this line of code,

CCAnimation *splashAnim = [CCAnimation animationWithFrames:splashAnimFrames delay:0.1f];

The variable splashAnimFrames is a mutable array containing string values

(
"splash-1.png",
"splash-2.png",
"splash-3.png",
"splash-4.png",
"splash-5.png",
"splash-6.png"
)

where as it should contain CCSpriteFrame objects instead. Check the documentation of CCAnimation for more information.

share|improve this answer
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.