关于cococs2d-x帧动画的制作

来源:互联网 发布:数据库原理精品课程 编辑:程序博客网 时间:2024/06/05 17:45

在这里介绍一本书这本书对于学习cococs2d-x的新手来很好用--“Cococs2d-x 3.x游戏开发实战”,内容很好例子也很不错,在这里介绍给大家,这本书百度云盘里面有,大家可以自己下载:http://www.sobaidupan.com/search.asp?wd=Cococs2d-x+3.x%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E5%AE%9E%E6%88%98

今天主要是对帧动画做了了解,大家有兴趣可以看一看

         //背景图片

Sprite * bg = Sprite::create("Resources\\Images\\loading\\Ball.png");
bg->setAnchorPoint(Vec2::ZERO);
bg->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2 + 50));
this->addChild(bg, 1);

         //设置精灵对象
auto sp = Sprite::create("Resources\\Images\\loading\\Note\\0.png");
sp->setAnchorPoint(Vec2::ZERO);
bg->addChild(sp);

       //创建动画对象,它是动画帧元素的集合对象,决定了动画帧的播放顺序以及时间间隔
auto animatio = Animation::create();
for (int i = 0; i < 19; i++)
{

                  //将单张图片作为精灵帧
animatio->addSpriteFrameWithFile(StringUtils::format("Resources\\Images\\loading\\Note\\%d.png", i));
}
//设置动画播放的属性,3s/15帧
animatio->setDelayPerUnit(3.0f / 40.0f);
//让精灵完成动画后恢复到初始状态
animatio->setRestoreOriginalFrame(true);

       //创建动作
auto animat = Animate::create(animatio);
//永久的执行此动画
auto action = RepeatForever::create(animat);
sp->runAction(action);

1 0
原创粉丝点击