cocos2dx3.0和老版本的帧动画

cocos2dx3.0版本


CCAnimate* IPanel::createAnimate(char* pngName, int firstNum, int count, float cellTime, int loop)

{

/***************************************cocos2dx老版本帧动画*****************************************/

CCArray* pArray = CCArray::create();

for(int i=firstNum; i

{  

char name[100];

sprintf(name, pngName, i);  

CCSpriteFrame* pframe = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name);   

pArray->push_back(pframe);

}  

   

CCAnimation* pAnimation = CCAnimation::createWithSpriteFrames(pArray, cellTime); 

pAnimation->setLoops(loop);


/************************************cocos2dx  3.0  版本帧动画***************************************/

CCAnimate* panimate = CCAnimate::create(pAnimation);

    

    Vector<SpriteFrame*> animFrames(50);

    

    char str[100] = {0};

    for(int i = firstNum; i < count; i++)

    {

        sprintf(str, pngName, i);

        auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName( str );

        animFrames.pushBack(frame);

    }

    

    auto animation = Animation::createWithSpriteFrames(animFrames, cellTime);

    animation->setLoops(loop);

    

    Animate* panimate = Animate::create(animation);

 

return panimate;

}


你可能感兴趣的:(cocos2dx)