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

《Cocos2d学习之路》三,学习使用TexturePacker创建动画效果

发布时间:2020-12-14 19:55:32 所属栏目:百科 来源:网络整理
导读:转载请说明出处:http://blog.csdn.net/lsmfeixiang/article/details/42214027 github地址:https://github.com/teffy/cocos2dx 这是一篇我个人在EOE发的blog《《Cocos2d学习之路》一,前序和闹钟》,由于eoe的blog系统实在是无言以对,我就把eoe上面的帖子

转载请说明出处:http://blog.csdn.net/lsmfeixiang/article/details/42214027

github地址:https://github.com/teffy/cocos2dx


这是一篇我个人在EOE发的blog《《Cocos2d学习之路》一,前序和闹钟》,由于eoe的blog系统实在是无言以对,我就把eoe上面的帖子以及blog是都转到csdn上来,原文地址:http://www.eoeandroid.com/blog-781265-51507.html


今天接着看教程,使用TexturePacker创建动画效果。

教程里的code是2.x的而且下载下来的资源缺少一些资源图,无奈在网上又搜索找了一个使用 TexturePacker创建动画效果的blog,这个里面有齐全的图片资源,但是code是oc的貌似,可怜我这屌丝还是win8系统,mac没有,oc看不懂,就使用前面的code和后面blog的图片资源。看图:

一、下载的TexturePacker是3.6的版本,跟之前的版本界面不太一样,是先选平台,如图

后面的操作差不多,然后可以保存项目,public sprite sheet到项目的Resources下。
二、code的变化
1、3.x可以使用SpriteFrameCacheSpriteFrameAnimation,代替原来的以CC开头的,当然API的参数列表也是有变化的,需要具体查看定义
2、使用Vector<T>代替CCArray进行容器管理

贴一下Code:
Animation* AnimationCreator::createAnimWithFrameNameAndNum(const char* name,int num,float delay,unsigned int loops){
SpriteFrameCache* cache = SpriteFrameCache::sharedSpriteFrameCache();
Vector<SpriteFrame*> framesVector(num);
SpriteFrame* spriteFrame = NULL;
for (int i = 1; i < num; i++){
spriteFrame = cache->spriteFrameByName(String::createWithFormat("%s%d.png",name,i)->getCString());
if (spriteFrame == NULL){
break;
}
framesVector.pushBack(spriteFrame);
}
Animation* animation = Animation::createWithSpriteFrames(framesVector,delay,loops);
animation->setRestoreOriginalFrame(true);
return animation;
}

auto xiaopao = Sprite::create("res/xiaobing.png");
xiaopao->setPosition(Vec2(visibleSize.width / 2 + origin.x,visibleSize.height / 2 + origin.y));
this->addChild(xiaopao);
SpriteFrameCache* cache = SpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("res/xiaobing.plist","res/xiaobing.png");
Animation* anim = AnimationCreator::createAnimWithFrameNameAndNum("xiaobing",8,0.1f,-1);
xiaopao->runAction(Animate::create(anim));

最后放一张效果图,其实是动的,不会做gif,有会的教教我,另外Android可运行


参考:
http://cn.cocos2d-x.org/tutorial/show?id=284
http://blog.csdn.net/u012945598/article/details/16988633
http://blog.csdn.net/time_anime/article/details/7754832

点击下载资源

(编辑:李大同)

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

    推荐文章
      热点阅读