General process of creating an animation:
1. Create the cache of the genie framework, add the corresponding animation file (plist) to it, and finally produce the animation through the cache of the animation set.
CCSpriteFrameCache * cache = CCSpriteFrameCache: sharedSpriteFrameCache (); cache-> addSpriteFramesWithFile ("animations/grossini. plist "); cache-> animation (" animations/images "," animations/images "); CCSpriteBatchNode * spritebatch = CCSpriteBatchNode: create (" animations/grossini.png "); // used for batch production genie CCArray * animFrames = CCArray: createWithCapacity (15); // dynamically generates arrays, similar to vecto R for (int I = 1; I <4; I ++) {// sprintf is used for string formatting. The main function is to write formatted data into a string. Sprintf (str, character ani_conch_character d.png ", 1) then the value of str becomes: ani_conch_1.png sprintf (str," grossini_blue_%02d.png ", I); // two digits. If not, complete CCSpriteFrame * frame = cache-> spriteFrameByName (str); animFrames-> addObject (frame);} animation = CCAnimation: createWithSpriteFrames (animFrames, 0.2f ); // create an animation set. the switching time is 0.2 s. // Add an animation to the Cache CCAnimationCache: sharedAnimationCache ()-> addAnimation (animation, "dance_blue "); // Add this animation set to the animation set cache and name it dance_blue CCAnimationCache * animCache = CCAnimationCache: sharedAnimationCache (); // share the animation set cache CCAnimation * normal = animCache-> animationByName ("dance"); // obtain the animation set cache CCAnimate * animN = CCAnimate: create (normal ); // create an animated CCSpriteFrameCache * cache = CCSpriteFrameCache: sharedSpriteFrameCache (); cache-> addSpriteFramesWithFile ("animations/grossini. plist "); cache-> addSpriteFramesWit HFile ("animations/arrays", "animations/grossini_gray.png"); CCSpriteBatchNode * spritebatch = CCSpriteBatchNode: create ("animations/grossini.png "); // used for batch production of the genie CCArray * animFrames = CCArray: createWithCapacity (15); // dynamically generated array, similar to vector for (int I = 1; I <4; I ++) {// sprintf is used for string formatting. The main function is to write formatted data into a string. Sprintf (str, character ani_conch_character d.png ", 1) then the value of str becomes: ani_conch_1.png sprintf (str," grossini_blue_%02d.png ", I); // two digits. If not, complete CCSpriteFrame * frame = cache-> spriteFrameByName (str); animFrames-> addObject (frame);} animation = CCAnimation: createWithSpriteFrames (animFrames, 0.2f ); // create an animation set. the switching time is 0.2 s. // Add an animation to the Cache CCAnimationCache: sharedAnimationCache ()-> addAnimation (animation, "dance_blue "); // Add the animation set to the animation set cache and name it dance_blue CCAnimationCache * animCache = CCAnimationCache: sharedAnimationCache (); // share the animation set cache CCAnimation * normal = animCache-> animationByName ("dance"); // obtain the animation set cache CCAnimate * animN = CCAnimate: create (normal ); // create an animation
2. directly upload multiple image files to generate animations
CCSprite * mainsprite = CCSprite: create ("catBody1.png"); CCAnimation * animation = CCAnimation: create (); animation-> addSpriteFrameWithFileName ("catBody1.png "); animation-> animation ("catBody2-4.png"); animation-> addSpriteFrameWithFileName ("catBody3.png"); animation-> animation ("catBody2-4.png"); animation-> setDelayPerUnit (0.1f ); // set the animation interval animation-> setRestoreOriginalFrame (true); // whether to return the first frame mainsprite-> runAction (CCRepeatForever: create (CCAnimate :: create (animation); CCSprite * mainsprite = CCSprite: create ("catBody1.png"); CCAnimation * animation = CCAnimation: create (); animation-> animation ("catBody1.png"); animation-> animation ("catBody2-4.png"); animation-> animation ("catBody3.png"); animation-> addSpriteFrameWithFileName ("catBody2-4.png "); animation-> setDelayPerUnit (0.1f); // set the animation interval animation-> setRestoreOriginalFrame (true); // whether to return the first frame mainsprite-> runAction (CCRepeatForever :: create (CCAnimate: create (animation )));