//采用spriteFrameCache创建sprite
void GameOverLayer::createSpriteUseFrameCache()
{
CCSpriteFrameCache* spriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
//读取plist文件,生成动画缓存
spriteFrameCache->addSpriteFramesWithFile("doggif/doglist.plist","doggif/doglist.png");
CCArray* array = new CCArray();
//遍历文件,生成动画数组
for(int i = 0; i<44; i++)
{
char str[10]="";
sprintf(str,"%d.jpg",i+1);
CCSpriteFrame* frame = spriteFrameCache->spriteFrameByName(str);
array->addObject(frame);
}
//创建动画
CCAnimation* anit = CCAnimation::createWithSpriteFrames(array,0.1);
CCAnimate* ani = CCAnimate::create(anit);
//循环动画
CCRepeatForever* repeat = CCRepeatForever::create(ani);
CCSprite* sprite = CCSprite::create();
CCSize size = CCDirector::sharedDirector()->getVisibleSize();
sprite->setPosition(ccp(size.width/2,size.height/2));
addChild(sprite);
//执行循环动画
sprite->runAction(repeat);
}
void GameOverLayer::createSpriteUseFrameCache()
{
CCSpriteFrameCache* spriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
//读取plist文件,生成动画缓存
spriteFrameCache->addSpriteFramesWithFile("doggif/doglist.plist","doggif/doglist.png");
CCArray* array = new CCArray();
//遍历文件,生成动画数组
for(int i = 0; i<44; i++)
{
char str[10]="";
sprintf(str,"%d.jpg",i+1);
CCSpriteFrame* frame = spriteFrameCache->spriteFrameByName(str);
array->addObject(frame);
}
//创建动画
CCAnimation* anit = CCAnimation::createWithSpriteFrames(array,0.1);
CCAnimate* ani = CCAnimate::create(anit);
//循环动画
CCRepeatForever* repeat = CCRepeatForever::create(ani);
CCSprite* sprite = CCSprite::create();
CCSize size = CCDirector::sharedDirector()->getVisibleSize();
sprite->setPosition(ccp(size.width/2,size.height/2));
addChild(sprite);
//执行循环动画
sprite->runAction(repeat);
}