In my spare time, I want to talk about creating Frame Animation in cocos2d-x,
Read from a plist file to create multiple frames,
First, we need to use a tool to generate a plist file for multiple frames of animation (hand-writing plist is too brainless ),
This plist contains multiple frames of animation information, and then we call the newly generated plist in the program,
The tool I used is the redbaby toolbox. You can download it for use. Founder has all the functions I currently use.
First, we need to combine all the single images into a large image (CUT/tile bar), and then save and export. plist, that is, PackSpr. plist,
2. In the animation editing bar, bind a new Image to the Root file, right-click the Image, name it die, and create a fixed frame Key Frame Animation. At this time, a single Image is generated to search for the Image block,
The start and end of an image are an animation, where the value is 1 and the subsequent continuous value and the image name suffix is also required. The first animation is ready to save the die. plist, the second animation also works the same way, but the image starts from the end of the previous image + 1 and is saved as a walk. plist,
Let's think about it. We still have multiple plist. Yeah, in fact, we still need one step to generate only one plist, that is, when we generate two animated file plist, we also generate two ani files. We only need to combine these two ani files into one plist. We open the role editing column, right-click in the blank area, create a new role class, name it RoleAni, add a new role, and name it RoleAni. Then add the actions one by one and add them to our animation file ani, Which is die and walk respectively, okay, save it as RoleAni. plist: At this time, plist is done. Let's call it in the program.
[Cpp]
CCSpriteFrameCache * frameCache = CCSpriteFrameCache: sharedSpriteFrameCache ();
FrameCache-> addSpriteFramesWithFile ("PackSpr. plist ");
// Purge previusly loaded animation
CCAnimationCache: purgeSharedAnimationCache ();
CCAnimationCache * animCache = CCAnimationCache: sharedAnimationCache ();
// Add an animation to the Cache
AnimCache-> addAnimationsWithFile ("RoleAni. plist ");
CCSize winSize = CCDirector: sharedDirector ()-> getWinSize ();
CCAnimation * die = animCache-> animationByName ("die ");
Die-> setRestoreOriginalFrame (true );
CCAnimate * animdie = CCAnimate: create (die );
CCSequence * seqdie = (CCSequence *) CCSequence: create (animdie, NULL );
CCSprite * sprdie = CCSprite: create ();
CCSpriteFrame * framedie = frameCache-> spriteFrameByName ("role_10.bmp ");
Sprdie-> setDisplayFrame (framedie );
Sprdie-> setPosition (ccp (winSize. width/2-100, winSize. height/2 ));
Sprdie-> setScale (0.5 );
AddChild (sprdie );
// Run the animation
Sprdie-> runAction (seqdie );
CCAnimation * walk = animCache-> animationByName ("walk ");
Walk-> setRestoreOriginalFrame (true );
CCAnimate * animwalk = CCAnimate: create (walk );
CCSequence * seqwalk = (CCSequence *) CCSequence: create (animwalk, NULL );
CCSprite * sprwalk = CCSprite: create ();
CCSpriteFrame * framewalk = frameCache-> spriteFrameByName ("role_1.bmp ");
Sprwalk-> setDisplayFrame (framewalk );
Sprwalk-> setPosition (ccp (winSize. width/2, winSize. height/2 ));
AddChild (sprwalk );
// Run the animation
Sprwalk-> runAction (seqwalk );
CCSpriteFrameCache * frameCache = CCSpriteFrameCache: sharedSpriteFrameCache ();
FrameCache-> addSpriteFramesWithFile ("PackSpr. plist ");
// Purge previusly loaded animation
CCAnimationCache: purgeSharedAnimationCache ();
CCAnimationCache * animCache = CCAnimationCache: sharedAnimationCache ();
// Add an animation to the Cache
AnimCache-> addAnimationsWithFile ("RoleAni. plist ");
CCSize winSize = CCDirector: sharedDirector ()-> getWinSize ();
CCAnimation * die = animCache-> animationByName ("die ");
Die-> setRestoreOriginalFrame (true );
CCAnimate * animdie = CCAnimate: create (die );
CCSequence * seqdie = (CCSequence *) CCSequence: create (animdie, NULL );
CCSprite * sprdie = CCSprite: create ();
CCSpriteFrame * framedie = frameCache-> spriteFrameByName ("role_10.bmp ");
Sprdie-> setDisplayFrame (framedie );
Sprdie-> setPosition (ccp (winSize. width/2-100, winSize. height/2 ));
Sprdie-> setScale (0.5 );
AddChild (sprdie );
// Run the animation
Sprdie-> runAction (seqdie );
CCAnimation * walk = animCache-> animationByName ("walk ");
Walk-> setRestoreOriginalFrame (true );
CCAnimate * animwalk = CCAnimate: create (walk );
CCSequence * seqwalk = (CCSequence *) CCSequence: create (animwalk, NULL );
CCSprite * sprwalk = CCSprite: create ();
CCSpriteFrame * framewalk = frameCache-> spriteFrameByName ("role_1.bmp ");
Sprwalk-> setDisplayFrame (framewalk );
Sprwalk-> setPosition (ccp (winSize. width/2, winSize. height/2 ));
AddChild (sprwalk );
// Run the animation
Sprwalk-> runAction (seqwalk );