0

The code below compiles and runs well in the init() section of the class, yet when I try to create a separate method for it, a CCSpriteFrame ended up null, I'd like to learn what conceptual assumption I gotten myself into this time =s

void SceneView::runZoo(Animal& animal, std::string attack) {
    //
    // Animation using Sprite BatchNode
    //
    std::string spriteName;
    CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    CCSize iSize = CCDirector::sharedDirector()->getWinSize();

    spriteName = "killerRabbit.plist";
    cache->addSpriteFramesWithFile(spriteName.c_str());

    spriteName = "killerRabbit1.png";
    sprite = CCSprite::createWithSpriteFrameName(spriteName.c_str());
    sprite->setPosition( ccp(iSize.width/2 - 160, iSize.height/2 - 40) );

    spriteName = "killerRabbit.png";
    CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(spriteName.c_str());
    spritebatch->addChild(sprite);
    this->addChild(spritebatch);

    CCArray* animFrames = CCArray::createWithCapacity(15);

    spriteName = "killerRabbit";
    char str[100] = {0};
    for(int i = 1; i <= 9; i++) {
        sprintf(str, (spriteName + "%d.png").c_str(), i);
        CCSpriteFrame* frame = cache->spriteFrameByName(str);
//Null here
        animFrames->addObject(frame);
//Null here
    }

    CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f);
    sprite->runAction( CCRepeatForever::create(CCAnimate::create(animation)) );
}

The actual error:

/** Appends an object. Behavior undefined if array doesn't have enough capacity. */
void ccArrayAppendObject(ccArray *arr, CCObject* object)
{
    CCAssert(object != NULL, "Invalid parameter!");
    object->retain();
    arr->arr[arr->num] = object;
    arr->num++;
}

That means that the CCSpriteFrameCache might be nulled for some reason, any ideas?

4

2 に答える 2