Cocos2d-x入门: 序列帧动画实现

Cocos2d-x入门: 序列帧动画实现,第1张

概述cocos2d-x 2.x   CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("<span style="font-family: Arial, Helvetica, sans-serif;">Splash</span><span style="font-family: Arial, Helvetica
cocos2d-x 2.x  
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithfile("<span >Splash</span><span >.pList");</span>CCArray* splashFrames = CCArray::create();    for (int i=1; i<=23; i++) {        const char* str = CCString::createWithFormat("Splash_%04d.png",i)->getCString();        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByname(str);        splashFrames->addobject(frame);            }    CCAnimation *splashAnim = CCAnimation::create();    splashAnim = CCAnimation::createWithSpriteFrames(splashFrames,0.02f);    CCAnimation *splashAnim = CCAnimation::createWithSpriteFrames(splashFrames,0.2);    splashAnim->setLoops(1);    CCAnimate *animate = CCAnimate::create(splashAnim);  CCSprite* animsprite = CCSprite::createWithSpriteFramename("<span >Splash_</span><span >0000.png");</span>    animsprite->runAction(animate);或者: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来组织帧序列,相对更加灵活.

2.x的两种方式更加pList的不同类型区分:frame和animal类型。

总结

以上是内存溢出为你收集整理的Cocos2d-x入门: 序列动画实现全部内容,希望文章能够帮你解决Cocos2d-x入门: 序列帧动画实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1067353.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存