代码说话:
CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache->addSpriteFramesWithFile("run.plist", "run.png");
CCSpriteFrame* frame = NULL;
CCArray* frameList = CCArray::create();
/* 创建精灵帧对象,添加到列表里 */
for(int i = 1; i <= 15; i++) {
frame = frameCache->spriteFrameByName(CCString::createWithFormat("run%d.png", i)->getCString());
frameList->addObject(frame);
}
/* 根据精灵帧对象创建动画对象 */
CCAnimation* animation = CCAnimation::createWithSpriteFrames(frameList);
animation->setLoops(-1); // 循环播放
animation->setDelayPerUnit(0.06f); // 每帧播放间隔
/* 创建动画动作 */
CCAnimate* animate = CCAnimate::create(animation);
/* 精灵执行动作 */
m_sprite->runAction(animate);