CCARRAY_VERIFY_TYPE(arrayOfAnimationFrames, CCAnimationFrame*); Question

I’m getting a SIGABRT which seems to imply that the type of object accepted is wrong, I’m following this tutorial:


while converting the code to c++, which ends up looking like this:

//    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"AnimBear.plist"];
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("bear.plist");
//    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"AnimBear.png"];
//    [self addChild:spriteSheet];
    CCSpriteBatchNode* spriteSheet = CCSpriteBatchNode::create("bear.png");
    this->addChild(spriteSheet);
//    NSMutableArray *walkAnimFrames = [NSMutableArray array];
//    for (int i=1; i<=8; i++) {
//        [walkAnimFrames addObject:
//         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
//          [NSString stringWithFormat:@"bear%d.png",i]]];
//    }
    CCArray* walkAnimFrames = new CCArray;
//    for (int i=1; i<=8; i++) {
        walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear1.png"));
//    }
// Hardcoded this in to test if the string concat had errors
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear2.png"));
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear3.png"));
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear4.png"));
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear5.png"));
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear6.png"));
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear7.png"));
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear8.png"));
//    CCAnimation *walkAnim = [CCAnimation 
//                             animationWithSpriteFrames:walkAnimFrames delay:0.1f];
    CCAnimation* walkAnim = CCAnimation::create(walkAnimFrames, 0.1f);
//    CGSize winSize = [[CCDirector sharedDirector] winSize];
//    self.bear = [CCSprite spriteWithSpriteFrameName:@"bear1.png"];
//    self.bear.position = ccp(winSize.width/2, winSize.height/2);
//    self.walkAction = [CCRepeatForever actionWithAction:
//                       [CCAnimate actionWithAnimation:walkAnim]];
//    [self.bear runAction:self.walkAction];
//    [spriteSheet addChild:self.bear];
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    this->bear = CCSprite::createWithSpriteFrameName("bear1.png");
    this->bear->setPosition(ccp(winSize.width/2, winSize.height/2));
    this->walkAction = CCRepeatForever::create(CCAnimate::create(walkAnim));
    this->bear->runAction(this->walkAction);
    spriteSheet->addChild(this->bear);

The error seems to originate from this line:

// return type is CCSpriteFrame*
    walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear1.png"));

The code seems to want an object of type CCAnimationFrame* but I’ve found no associated method that can return an object of that type in:

 walkAnimFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->

Problems persist even when I try to typecast it like this:

walkAnimFrames->addObject( (CCAnimationFrame*)CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bear1.png") );

Can anyone spot what’s wrong? =s

I had the same problem with cocos2d-x 2.x, when calling CCAnimation::create(frames, rate). In my case, I had to use CCAnimation::createWithSpriteFrames(frames, rate) instead. The CCAnimation::create() requires a CCArray of (CCAnimationFrames *), and we’re using (CCSpriteFrame *).

Hope it helps