1

在我创建它们的那一刻,它们似乎都自动释放了 =s

void SceneView::createAnimation(KillerRabbit* killerRabbit, std::string animation) {
    CCArray* animFrames = CCArray::createWithCapacity(15);
    int first = std::stoi(killerRabbit->spriteSheetMap[animation]["FIRST"]);
    int last = std::stoi(killerRabbit->spriteSheetMap[animation]["LAST"]);
    char str[100] = {0};
    for (int i = first; i <= last; i++) {
        // Obtain frames by alias name
        sprintf(str, (killerRabbit->spriteSheetMap[animation]["KEY"]+"[%d].png").c_str(), i);
        CCSpriteFrame* frame = sharedSpriteFrameCache->spriteFrameByName(str);
        animFrames->addObject(frame);
    }

    spriteAnimationsMap[killerRabbit->spriteName][animation] = CCAnimation::createWithSpriteFrames(animFrames, 0.1f);
    // 14 frames * 1sec = 14 seconds
    rabbitSprites[killerRabbit->spriteName][animation]->
    runAction(CCRepeatForever::create(CCAnimate::create(spriteAnimationsMap[killerRabbit->spriteName][animation])));
}

如果我省略这部分代码:

rabbitSprites[killerRabbit->spriteName][animation]->
runAction(CCRepeatForever::create(CCAnimate::create(spriteAnimationsMap[killerRabbit->spriteName][animation])));

并尝试访问对象:

spriteAnimationsMap[killerRabbit->spriteName][animation]

在使用另一种方法的代码的后面部分中,该地图内的对象将被自动释放,我如何保留它以便以后可以使用存储在其中的不同动画?

4

1 回答 1

1

哦,愚蠢的我,我不得不这样做:

spriteAnimationsMap[killerRabbit->spriteName][animation]->retain();
于 2013-04-04T21:45:36.053 回答