CCAnimation* SgGameResultAni::CreateKessenEffect(ODEInt32 framecount,string spriteFilename,float var_time)
{
frameAyyay = CCArray::createWithCapacity(framecount);
for (int i=1;i<=framecount;++i)
{
char filename[40];
sprintf(filename,spriteFilename.c_str(),i);
CCTexture2D *fileTexture = CCTextureCache::sharedTextureCache()->addImage(filename);
CCSpriteFrame *frame = CCSpriteFrame::createWithTexture(fileTexture,CCRect(0,0,fileTexture->getContentSize().width,fileTexture->getContentSize().height));
//CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename);
frameAyyay->addObject(frame);
CCTextureCache::sharedTextureCache()->removeTextureForKey(filename);
}
animation = CCAnimation::createWithSpriteFrames(frameAyyay,var_time);
//animation->retain();
return animation;
}
</pre><p>使用上面的成员函数生成 animation 然后在使用的地方这样调用</p><p></p><pre code_snippet_id="490189" snippet_file_name="blog_20141020_2_94055" name="code" class="cpp"> CCAnimation *sg_win_ani = sg_ani->CreateKessenEffect(SG_WINEFFECT_FRAME_NUM,IMAGE_PATH_GAME_RESULT_WIN,SG_ANI_VAR_TIME);
CCAnimate *animate = CCAnimate::create(sg_win_ani);//这里创建了动画的Action
CCActionInterval* win_seq = (CCActionInterval*)(CCSequence::create( animate,CCDelayTime::create(0.1f),CCRemoveSelf::create(true),pCallbackFun,NULL));
CCSprite *win_sp = CCSprite::create("win_1.png");
win_sp->setPosition(pk_exbet_widget.getPosition());
win_sp->setScale(ui_main_scale);
addChild(win_sp,9);
win_sp->runAction(win_seq);
注意:这个如果图片大小不一致就需要对每一帧设置位置了