cocos2d-x 创建帧动画
看到好多人问如何用cocos2d-x创建帧动画,其实用cocos2d-x很容易创建帧动画。我就写一遍吧。
- void MyClass::initMyAnim()
- {
- /**
- //可以在程序载入的时候预加载这些动画资源,然后在cache中读取
- CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
- cache->addSpriteFramesWithFile("run.plist", "run.png");
- */
- CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
- CCMutableArray<CCSpriteFrame*>* animFrames = new CCMutableArray<CCSpriteFrame*>(12);
- char str[64] = {0};
- for(int i = 1; i <=12; i++)
- {
- sprintf(str, "run%04d.png", i);
- CCSpriteFrame* frame = cache->spriteFrameByName( str );
- animFrames->addObject(frame);
- }
- CCAnimation* animation = CCAnimation::animationWithFrames(animFrames,0.4f);
- CCActionInterval* action=CCAnimate::actionWithAnimation(animation,true);
- CCFiniteTimeAction *myRun= CCSequence::actions(action,CCCallFunc::actionWithTarget(this,callfunc_selector(MyClass::callBackRun)),NULL);
- myRun->retain();
- animFrames->release();
- }
CCCallFunc用来做动画回调用,没有回调的话,就不用了。myRun->retain()后记得release掉。
OK,是不是很简单。记录一笔。
相关推荐
Cricket 2020-05-31
woxmh 2019-12-30
CaptainCTR 2019-12-19
86463960 2013-07-15
80487916 2013-07-06
86463960 2013-08-28
BenOnceMore 2013-08-26
89741733 2014-03-20
86201242 2014-05-13
85427010 2014-09-04
文艺小青年 2015-03-26
cooclc 2015-03-26
85427010 2015-05-22
frankwang 2015-05-19
80487916 2015-05-18
进入场景而且过渡动画结束时候触发。提示 GameScene场景中的继承于节点,这些生命周期事件根本上是从Node继承而来。事实上所有Node对象都有这些事件,具体实现代码与GameScene场景类似。
87921036 2015-05-12
yizhiyanstart 2011-12-31
oQiXiLaoTou 2012-09-25