Monkey original, reprinted. Reprinted Please note: Reprinted from cocos2d Development Network --cocos2dev.com, thank you!
Original address: http://www.cocos2dev.com /? P = 279
I previously introduced the creation of various animation methods for cocos2d-x, But 2.0 modified some methods, and many friends asked me how to create an animation, today I will introduce the animation creation method of 2.0, I hope you can see that you can learn how to create animations in other ways.
1. Use SWF to create an animation.
1. Use the TP tool to export SWF to a plist file.
2. How to create an animation:
#define kDelayPerUnit 0.08fCCActionInterval* SAAnimationManager::createRFAnimFormSwf(const char* swfName,int frames){ char str1[100] = {0}; char str2[100] = {0}; CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); sprintf(str1, "%s.plist", swfName); sprintf(str2, "%s.png", swfName); cache->addSpriteFramesWithFile(str1,str2); CCArray* animFrames = CCArray::create(15); for(int i = 0; i < frames; i++){ sprintf(str2, "%s.swf/%04d", swfName,i); CCSpriteFrame *frame = cache->spriteFrameByName(str2); animFrames->addObject(frame); } CCAnimation *animation = CCAnimation::create(animFrames, kDelayPerUnit); cache->removeSpriteFramesFromFile(str1); return CCRepeatForever::create(CCAnimate::create(animation));}
Parameter introduction:
Const char * swfname: SwF name. Remember that the SWF name should be the same as that of plist. If your SWF name is different from the exported plist name, you will find that the name of each frame in the pilst is the SWF name, And the plist is your name, there will be two different names, so you will pay attention to the name when loading each frame.
Int frames: the number of frames in SWF.
In this way, a permanent animation is returned, and you can use a Sprite-> runaction () method to display the action.