《初学cocos2d-x》- 动画TexturePacker(3)

来源:互联网 发布:shiro java 判断权限 编辑:程序博客网 时间:2024/05/10 04:49

TexturePacker这个词从字面来说就是Texture(纹理) + Packer(打包)。它是一款把若干资源图片拼接为一张大图的工具。

TexturePacker做出来的图是一张大图,从性能以及使用上来讲都是特别优的,具体网上说的太多了,如果有兴趣可以查查,这里暂时不说,下面说一下简单的使用,以及代码

1.下载

什么版本都有,你懂的,自己google 百度一下

2.新建一个项目

Add Folder

选择你的资源,可以多次添加(如何删除,暂时我没看到)

这时候在右侧Sprites窗口就可以查看资源的内容了

3.sava and output

Data file 选择输出目录.plis结尾

Texture file 选择输出目录.png结尾

Geometry 下的 Max.width Max.height 最好是1000 1000(没仔细研究)

最后选择Publish

如下图



把.plist 和 .png拷贝到项目的资源目录下面,然后可以写代码了。


下面看代码部分


//初始化资源    CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache();    cache->addSpriteFramesWithFile("superman_pic1.plist", "superman_pic1.png");    CCSprite *sprite=CCSprite::create();    sprite->setPosition(ccp(s.width/2,s.height/2));    addChild(sprite,1);    CCArray* arry=CCArray::create();    char str[100]={0};    for(int i=1;i<5;i++)    {        sprintf(str, "cloud_%d.png", i);        CCSpriteFrame* frame=cache->spriteFrameByName(str);        arry->addObject(frame);    }        CCAnimation *animation=CCAnimation::createWithSpriteFrames(arry,0.2f);    animation->createWithSpriteFrames(arry);    CCAnimate *animate=CCAnimate::create(animation);    sprite->runAction(CCRepeatForever::create(animate->reverse()));

看出来,只有初始化部分不一样,其他步骤跟简单的创建一个动画没什么区别了。

如果你不了解怎么创建简单的动画,可以看一下http://blog.csdn.net/dadagm/article/details/9395923

上面只是简单的创建以及实现,关于TexturePacker还有很多好玩的功能,大家慢慢研究。 

原创粉丝点击