標籤:cocos2d-x入門 序列幀動畫實現 cocos2d-x入門 createwithspritefram 獨立開發人員er
cocos2d-x 2.x
CCArray* splashFrames = CCArray::createWithCapacity(16); for (int i=1; i<=23; i++) { const char* str = CCString::createWithFormat("Splash_%04d.png",i)->getCString(); CCSpriteFrame* frame = cache->spriteFrameByName(str); splashFrames->addObject(frame); } CCAnimation *splashAnim = CCAnimation::create(); splashAnim = CCAnimation::createWithSpriteFrames(splashFrames, 0.02f);或者:CCAnimationCache* animationCache = CCAnimationCache::sharedAnimationCache();animationCache->addAnimationsWithFile("dealer_smile_ani.plist");CCAnimation* animation = animationCache->animationByName("dealer_smile_ani");nimSprite->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCAnimate::create(animation), CCDelayTime::create(2.5f))));
Cocos2d-x 3.x
Vector<SpriteFrame*> splashFrames; for (int i=1; i<=23; i++) { const char* str = CCString::createWithFormat("Splash_%04d.png",i)->getCString(); SpriteFrame* frame = cache->getSpriteFrameByName(str); splashFrames.pushBack(frame); } Animation *splashAnim = Animation::create(); splashAnim = Animation::createWithSpriteFrames(splashFrames, 0.02f);
很明顯,2.x與3.x的實現方式,最大的區別在於3.x用不定長的Vector來組織幀序列,相對更加靈活
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Cocos2d-x入門: 序列幀動畫實現