What I’m doing is like this, and I also agree for better and simpler function call.
CCSprite* Utils::createAnimation(const char* pPlist,const char* pCommonName,uint32_t pStartFrame,uint32_t pEndFrame,float pFrameDelay,bool isLoop)
{
CCSpriteFrameCache* cacher = CCSpriteFrameCache::sharedSpriteFrameCache();
cacher->addSpriteFramesWithFile(pPlist);
const int kNumberOfFrames = pEndFrame + 1; CCArray* frames = new CCArray; frames->initWithCapacity(kNumberOfFrames); for( int i = pStartFrame; i < kNumberOfFrames; i++ ) { CCString* filename = CCString::createWithFormat("%s%d.png",pCommonName, i); frames->addObject(cacher->spriteFrameByName(filename->getCString())); }
CCSprite* sprite = new CCSprite; CCString* dummy = CCString::createWithFormat("%s1.png",pCommonName); sprite->initWithSpriteFrameName(dummy->getCString());
CCAnimation* anim = new CCAnimation; anim->initWithSpriteFrames(frames, pFrameDelay);
if(isLoop) sprite->runAction(CCRepeatForever::create(CCAnimate::create(anim))); else sprite->runAction(CCAnimate::create(anim));
//cacher->release(); return sprite;}