plist文件读取并动画

来源:互联网 发布:linux性能监控命令 编辑:程序博客网 时间:2024/04/27 14:57

1.读入plist文件

CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache();cache->addSpriteFramesWithFile("000.pv.plist");CCSprite *sprite=CCSprite::createWithSpriteFrame(cache->spriteFrameByName("attack_type1_d_0000.png"));

2.形成CCAnimation

//"attack_type1_d_0000.png""attack_type1_d_0001.png""attack_type1_d_0002.png"...CCAnimation *HelloWorld::GetAnimate(const char *name,const int count,float delay)//编号为:0~count-1的png图片形成动画(name为共同前缀){CCArray *a=CCArray::array();char keyname[100];for(int i=0;i<6;++i){sprintf(keyname,"%s%d.png",name,i);a->addObject(cache->spriteFrameByName(keyname));}// CCAnimation *animation = CCAnimation::animationWithSpriteFrames(a,delay); return animation;}

3.使用GetAnimate,对一个CCSprite做action操作

CCAnimation *animation=GetAnimate("attack_type1_l_000",6,0.2f);CCRepeat *repeat=CCRepeat::actionWithAction(CCAnimate::actionWithAnimation(animation),1);sprite->runAction(repeat);


注:如果希望动画回到某一帧:例如(返回动画的前一帧)

CCAnimation *animation=GetAnimate("attack_type1_l_000",6,0.2f);//add codeCCSpriteFrame *last_frame=sprite->displayFrame();//得到上一帧animation->addSpriteFrame(last_frame);//设置最后一帧CCRepeat *repeat=CCRepeat::actionWithAction(CCAnimate::actionWithAnimation(animation),1);


PS.

1.显示FPS的最上面显示的是需要绘制涂图元的数目。

原创粉丝点击