Method 1: use multiple sets of names to display different single-image png based on a certain rule,
[Cpp]
// Create a cache
CCSpriteFrameCache * cache = CCSpriteFrameCache: sharedSpriteFrameCache ();
Char strPlist [64] = {0 };
Char strPng [64] = {0 };
Sprintf (strPlist, "fei. plist ");
// Sprintf (strPng, "fei. pvr. ccz ");
Sprintf (strPng, "fei.png ");
Cache-> addSpriteFramesWithFile (strPlist, strPng );
// Create each animation frame and read it from the cache.
CCMutableArray <CCSpriteFrame *> * animFrames = new CCMutableArray <CCSpriteFrame *> (6 );
Char str [64] = {0 };
For (int I = 1; I <= 6; I ++)
{
Sprintf (str, "Apsara 04d.png", I );
CCSpriteFrame * frame = cache-> spriteFrameByName (str );
AnimFrames-> addObject (frame );
}
CCAnimation * animation = CCAnimation: animationWithFrames (animFrames, 0.04f );
CCRepeatForever * mFly = CCRepeatForever: actionWithAction (CCAnimate: actionWithAnimation (animation, false ));
AnimFrames-> release ();
Cache-> removeSpriteFramesFromFile (strPlist );
This code is from Baidu on the Internet. Http://blog.csdn.net/yanghuiliu/article/details/6933421
Another way is to add multiple images to a joint graph, which saves more disk space.
[Cpp]
// Composite graph
CCTexture2D * birdTexture = CCTextureCache: sharedTextureCache ()-> addImage ("bird2.png ");
CCMutableArray <CCSpriteFrame *> * myArray = new CCMutableArray <CCSpriteFrame *> (3 );
CCSpriteFrame * myframe1 = CCSpriteFrame: frameWithTexture (birdTexture, CCRect (1,379 ));
CCSpriteFrame * myframe2 = CCSpriteFrame: frameWithTexture (birdTexture, CCRect (1,411 ));
CCSpriteFrame * myframe3 = CCSpriteFrame: frameWithTexture (birdTexture, CCRect (1,508 ));
CCSpriteFrame * myframe4 = CCSpriteFrame: frameWithTexture (birdTexture, CCRect (1,538 ));
MyArray-> addObject (myframe1); www.2cto.com
MyArray-> addObject (myframe2 );
MyArray-> addObject (myframe3 );
MyArray-> addObject (myframe4 );
CCAnimation * animation = CCAnimation: animationWithFrames (myArray, 1.0f );
CCRepeatForever * myaction = CCRepeatForever: actionWithAction (CCAnimate: actionWithAnimation (animation, false ));
CCSprite * mybird = CCSprite: spriteWithSpriteFrame (myframe1 );
This-> addChild (mybird );
Mybird-> setPosition (ccp (200,300 ));
Mybird-> runAction (myaction );
MyArray-> release ();