This is the most basic code of creating and playing an animation in cocos2d:
auto cacher = SpriteFrameCache::getInstance();
cacher->addSpriteFramesWithFile("emad-running.plist");
Sprite* someSprite = Sprite::create();
// load all the animation frames into an array
Vector<SpriteFrame*> frames;
for (int i = 0; i <= 10; i++)
{
stringstream ss;
ss << "run_" << i << ".png";
frames.pushBack(cacher->getSpriteFrameByName(ss.str()));
}
// play the animation
Animation* anim = Animation::createWithSpriteFrames(frames, 0.05f);
someSprite->runAction(Animate::create(anim));
someSprite->setPosition(X, Y);
this->addChild(someSprite);
And for creating some file like "emad-running.plist", I suggest Texture Packer
. This tool support cocos2d fully. you can import your separated image, and Texture Packer give you two file:
- "emad-running.plist"
- "emad-running.pvr" OR "emad-running.png" OR ...
This two file complete each other and in code you just need to refer.plist
and you are done. :)
This is how you do in TexturePacker:

(source: raywenderlich.com)