您的位置:首页 > 移动开发 > Cocos引擎

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

2015-04-03 11:47 239 查看
//首先创建一个Vector来存放精灵动画

Vector<SpriteFrame*> allFrame;

//添加每一帧

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

auto sf=SpriteFrame::create(

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

Rect(0,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的小白有用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: