CCAnimation之 不指定帧数来创建动画

<1>创建

CCAnimation* AnimationUtil::createAnimationWithSingleName( const char* singleName ) 
{
	CCSpriteFrameCache* spriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
	int index = 1;
	CCSpriteFrame* frame = NULL;
	CCArray* frameArray = CCArray::create();
	do 
	{
		frame = spriteFrameCache->spriteFrameByName(
			CCString::createWithFormat("%s%d.png", singleName, index)->getCString());
		if(frame == NULL) 
			break;	
		frameArray->addObject(frame);
		index++;
		
	} while (true);
	return CCAnimation::createWithSpriteFrames(frameArray);
}
<2>使用

CCAnimation* heroAnim = AnimationUtil::sharedAnimationUtil()->createAnimationWithSingleName("hero1_atk");
heroAnim->setLoops(-1);
heroAnim->setDelayPerUnit(0.1f);
sprite->runAction(CCAnimate::create(heroAnim));


你可能感兴趣的:(CCAnimation之 不指定帧数来创建动画)