cocos2d-3.2 逐帧动画播放

来源:互联网 发布:明教知乎 编辑:程序博客网 时间:2024/05/21 11:35

动画实现的基本流程:


1.定义向量保存动画的所有帧

Vector<SpriteFrame *> allframe;


for(int i=1;i<10;i++)

{

 SpriteFrame * sf=SpriteFrame::create(

                   StringUtils::format("run%d.png",i),

                   Rect(0,0,w,h) );

allframe.pushBack(sf);

}

2.创建动画

Animation * animation01=Animation::createWithSpriteFrames(allframe);

animation01->setDelayPerUnity(0.3);

3.创建动作

Animate *animate01=Animate::create(animation01);

4.包装动作

Action * act=RepeatForEver::create(animate01);

5.让一个Sprite执行动作

Sprite * sp=Sprite::create();

sp->runAction(act);

0 0