cocos2d+TexturePackerGUI动画制作

转载出处:http://blog.csdn.net/oyangyufu/article/details/25168047

程序效果图:



1、下载安装TexturePackerGUI

地址:http://www.codeandweb.com/texturepacker

2、制作plist文件和png图片

打开TexturePackerGUI,将动画素材拖拽至TexturePackerGUI图片区,填写Output路径及名称,点击工具栏Publish,生成plist、png文件,然后将此2文件放至项目Resources下:



编写程序:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. bool HelloWorld::init()  
  2. {  
  3.     if ( !CCLayer::init() )  
  4.     {  
  5.         return false;  
  6.     }  
  7.       
  8.     CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();  
  9.     CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();  
  10.     CCMenuItemImage *pCloseItem = CCMenuItemImage::create(  
  11.                                         "CloseNormal.png",  
  12.                                         "CloseSelected.png",  
  13.                                         this,  
  14.                                         menu_selector(HelloWorld::menuCloseCallback));  
  15.       
  16.     pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,  
  17.                                 origin.y + pCloseItem->getContentSize().height/2));  
  18.   
  19.     CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);  
  20.     pMenu->setPosition(CCPointZero);  
  21.     this->addChild(pMenu, 1);  
  22.   
  23.     //装载plist文件  
  24.     CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("izmuo.plist""izmuo.png");  
  25.     CCArray *array = CCArray::create();  
  26.     char ptr[10]={0};  
  27.   
  28.     //获取每一帧动画,遍历图片名字  
  29.     for (int i=1; i<10; i++)  
  30.     {  
  31.         sprintf(ptr, "%d.png", i);  
  32.         CCLOG("ptr: %s",ptr);  
  33.         CCSpriteFrame *spriteframe = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(ptr);  
  34.         array->addObject(spriteframe);  
  35.   
  36.     }  
  37.     //根据帧序列表创建动画对象,指定播放速度  
  38.     CCAnimation *animation = CCAnimation::createWithSpriteFrames(array,0.2f);  
  39.     //根据动画创建动画动作  
  40.     CCAnimate *animate = CCAnimate::create(animation);  
  41.     CCSprite *sprite = CCSprite::create();  
  42.   
  43.     //开始执行动作  
  44.     sprite->setScale(0.5);  
  45.     sprite->runAction(CCRepeatForever::create(animate));  
  46.     sprite->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));  
  47.     this->addChild(sprite);  
  48.       
  49.     return true;  
  50. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值