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

前端之家收集整理的这篇文章主要介绍了寒風的Cocos2dx之旅之如何实现一个动画的播放前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//首先创建一个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的小白有用。

原文链接:https://www.f2er.com/cocos2dx/343622.html

猜你在找的Cocos2d-x相关文章