加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

寒風的Cocos2dx之旅之如何实现一个动画的播放

发布时间:2020-12-14 20:46:42 所属栏目:百科 来源:网络整理
导读://首先创建一个Vector来存放精灵动画 VectorSpriteFrame* allFrame; //添加每一帧 for(int i=0;i=10;i++){ auto sf=SpriteFrame::create( StringUtils::format("walk0%d.png",i, Rect(0,78,132 ) ); allFrame.pushBack( sf ); } //创建动画Animation auto an

//首先创建一个Vector来存放精灵动画

Vector<SpriteFrame*> allFrame;

//添加每一帧

for(int i=0;i<=10;i++){

auto sf=SpriteFrame::create(

StringUtils::format("walk0%d.png",i,

Rect(0,78,132));

allFrame.pushBack(sf);

}

//创建动画Animation

auto animation=Animation::createWithSpriteFrames(allFrame,0.3);

//创建动作animate

auto animate=Animate::create(animation);

auto sp=Sprite::create();

this->addChild(sp);

//创建一个Sprite来执行动画

sp->runaction(RepeatForever::create(animate));

sp->setPosition(Vec2(30,180));

 


希望对刚接触Cocos的小白有用。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读