zoukankan      html  css  js  c++  java
  • cocos2d-x 帧序列的动画播放 (简单的方法是AnimatePacker工具的使用)

    一.用TexturePacker-2.4.5工具做动画(要包含#include "AnimatePacker.h"文件

    1:用TexturePacker-2.4.5工具将序列图加载到大图中生成plist文件加载到项目中

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("quest.plist"),CCTextureCache::sharedTextureCache()->textureForKey("quest.png");

    2:AnimatePacker工具的使用

    (1)Plists:将Plist文件,拖动plist文件到AnimatePacker窗口上,就可以加载。
    (2)Animations:所有的动作列表,点击“摄像机”按钮可以新建动作,双击可以编辑Name为(”portraitAnimiton“也就是xml中保存的这段帧动画的key值)和Delay。
    (3)SpriteFrames:当前Animation对应的SpriteFrames列表,拖动可以排序。
    (4)Sprites:所有的备选Spirte,你可以拖动Spirte到SpriteFrames框下面。
    (5)保存生成一个xml文件加载到项目中:代码如下: 
     
    AnimatePacker::getInstance()->loadAnimations("portraitAnimitionSave.xml");
    //创建一个执行此段动画的精灵
    CCSprite *lockSprite = CCSprite::create();

    lockSprite->setPosition(ccp(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.5f));
    this->addChild(lockSprite, 1);

    lockSprite ->runAction(AnimatePacker::getInstance()->getAnimate("portraitAnimiton"));

    另外你也可以让这段动画加入动作序列中和其他动画一块执行代码如下:

    CCSequence *PotraitSequence = CCSequence::create(deleteLockSprite, AnimatePacker::getInstance()->getAnimate("portraitAnimiton"), afterAnimitionAction, NULL);
    lockSprite->runAction(PotraitSequence);

    二.普通的序列图动画的创建 这个也是要提前将序列图加载成大图plist加载到资源中

    //1:创建帧缓存

    CCSpriteFrameCache* pCacheObject = CCSpriteFrameCache::sharedSpriteFrameCache();

    CCSize size = CCDirector::sharedDirector()->getWinSize();

    //2:创建帧动作的存储数组

    CCArray *pSpriteFrameArray=new CCArray();

    //3:循环将序列图加载到帧缓存和数组中

    for(unsigned int Index = 1; Index <= 32; Index++)

    {
    CCString *stringName;
     if (Index < 10) {
      stringName = CCString::createWithFormat("Animation_portrait_locked_000%d.png", Index);
     }
     else {
      stringName = CCString::createWithFormat("Animation_portrait_locked_00%d.png", Index);
     }
     CCSpriteFrame* pSpriteFrame = pCacheObject->spriteFrameByName(stringName->getCString());
     pSpriteFrameArray->addObject(pSpriteFrame);
    }

    //4:创建一个动画对象

    CCAnimation *animationObject = CCAnimation::createWithSpriteFrames(pSpriteFrameArray, 0.05f);

    //5:创建执行动画的精灵
    CCSprite *pSprite = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Animation_portrait_locked_0001.png"));
    pSprite->setScale(1.8f);
    pSprite->setPosition(ccp(pSprite->getContentSize().width * 0.73f, pSprite->getContentSize().height * 0.72f));
    this->addChild(pSprite, 1);

    //6动作序列

    CCActionInterval* actionAnimition = CCAnimate::create(animationObject);
    CCCallFuncN * deleteLockSprite = CCCallFuncN::create(this, callfuncN_selector(PlayerPortraitSprite::deleteLockSpriteCallBack));
    CCCallFuncN * afterAnimitionAction = CCCallFuncN::create(this, callfuncN_selector(PlayerPortraitSprite::afterPlayAnimitionCallBack));

    CCSequence *PotraitSequence = CCSequence::create(deleteLockSprite, actionAnimition, afterAnimitionAction, NULL);
    pSprite->runAction(PotraitSequence);

    //7:释放数组对象
    pSpriteFrameArray->release();
    }

  • 相关阅读:
    用 Python 脚本实现对 Linux 服务器的监控
    linux系统常用命令
    一小时学会用Python Socket 开发可并发的FTP服务器!!
    Python获取程序运行目录和脚本目录
    哪些情况会导致OOM
    如何查看端口状态
    wait(),sleep(),notify(),join()
    cookie和session的区别与会话跟踪技术
    TCP的可靠性
    OSI和TCP/IP的对比+IP地址分类
  • 原文地址:https://www.cnblogs.com/ruzhuan/p/3438149.html
Copyright © 2011-2022 走看看