看到好多人问如何用cocos2d-x创建帧动画,其实用cocos2d-x很容易创建帧动画。我就写一遍吧。
- void MyClass::initMyAnim()
- {
-
-
-
-
-
- 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,是不是很简单。记录一笔。