zoukankan      html  css  js  c++  java
  • cocos2dx之TexturePacker使用

    TexturePacker用来把大量图片批量导入,简化开发,直接贴代码

    用来生成plist的原始图为A1_0.png到A1_3.png

     1    CCSize size = CCDirector::sharedDirector()->getWinSize();  //获得屏幕的尺寸
     2     
     3     CCArray* pArray = CCArray::createWithCapacity(4);
     4     CCSpriteFrameCache* pCache = CCSpriteFrameCache::sharedSpriteFrameCache();  //获得SpriteFrame的缓存
     5     pCache->addSpriteFramesWithFile("attack.plist");
     6     CCSprite* pSprite = CCSprite::createWithSpriteFrameName("A1_0.png");  //用attack.plist中的第一张图片名字创建一个精灵
     7     pSprite->setPosition(ccp(size.width/2,size.height/2));  //设置精灵的坐标
     8     
     9     
    10     char name[20];
    11     for(int i=0; i<4; i++)  //将plist中的图片都加载,放到array中
    12     {
    13         sprintf(name, "A1_%d.png", i);
    14         CCSpriteFrame* pframe = pCache->spriteFrameByName(name);
    15         pArray->addObject(pframe);
    16     }
    17     
    18     CCAnimation* pAnimation = CCAnimation::createWithSpriteFrames(pArray,0.2f);  //用array中的spriteframe创建一个animation,每帧间隔0.2s
    19     CCAnimate* panimate = CCAnimate::create(pAnimation);
    20     
    21     pSprite->runAction(CCRepeatForever::create(panimate));
    22     
    23     this->addChild(pSprite);
     
  • 相关阅读:
    mysql 优化
    对象的特征
    对象的回收机制
    对象产生的过程
    python 内容查询小助手
    python笔记
    python安装MySQLdb模块
    python笔记
    python笔记
    定期删除备份文件,节省磁盘空间脚本
  • 原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/3099266.html
Copyright © 2011-2022 走看看