Reprinted please indicate the source: http://blog.csdn.net/oyangyufu/article/details/25168047
Program:
1. Download and install TexturePackerGUI
Address: http://www.codeandweb.com/texturepacker
2. Create a plist file and a png image.
Open TexturePackerGUI, drag the animation material to the TexturePackerGUI image area, enter the Output path and name, click Publish on the toolbar, generate the plist and png files, and then place the two files under the project Resources:
Program writing:
Bool HelloWorld: init () {if (! CCLayer: init () {return false;} CCSize visibleSize = CCDirector: sharedDirector ()-> getVisibleSize (); CCPoint origin = CCDirector: shareddire () -> getVisibleOrigin (); CCMenuItemImage * pCloseItem = CCMenuItemImage: create ("Custom", "CloseSelected.png", this, menu_selector (HelloWorld: menuCloseCallback )); pCloseItem-> setPosition (ccp (origin. x + visibleSize. width-pCloseItem-> getContentSize (). width/2, origin. y + pCloseItem-> getContentSize (). height/2); CCMenu * pMenu = CCMenu: create (pCloseItem, NULL); pMenu-> setPosition (CCPointZero); this-> addChild (pMenu, 1 ); // load the plist file CCSpriteFrameCache: sharedSpriteFrameCache ()-> addSpriteFramesWithFile ("izmuo. plist "," izmuo.png "); CCArray * array = CCArray: create (); char ptr [10] = {0}; // get each frame of animation, traverse image name for (int I = 1; I <10; I ++) {sprintf (ptr, "d.png", I); CCLOG ("ptr: % s ", ptr); CCSpriteFrame * spriteframe = CCSpriteFrameCache: Adjust ()-> spriteFrameByName (ptr); array-> addObject (spriteframe);} // create an animation object based on the frame sequence table, specify the playback speed CCAnimation * animation = CCAnimation: createWithSpriteFrames (array, 0.2f); // create an animation action based on the animation CCAnimate * animate = CCAnimate: create (animation ); CCSprite * sprite = CCSprite: create (); // start to execute the action sprite-> setScale (0.5); sprite-> runAction (CCRepeatForever: create (animate )); sprite-> setPosition (ccp (visibleSize. width/2, visibleSize. height/2); this-> addChild (sprite); return true ;}