欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11775745
本来想写一下帧动画的,搜了一下网上好像有一大把,就懒得写了,直接贴代码。
// 精灵帧缓存 CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); // 添加 plist文件到缓存 cache->addSpriteFramesWithFile("lightning.plist"); // 创建数组用来存放帧序列 CCArray *animFrames = CCArray::create(); char str[64] = {0}; for (int i = 1; i <= 18; ++i) { sprintf(str, "lightning%02d.png", i); CCSpriteFrame *frame = cache->spriteFrameByName(str); CCLOG(str); // 添加帧到数组 animFrames->addObject(frame); } // 用帧序列生成帧动画信息,设定帧间隔时间 CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.08); animation->setRestoreOriginalFrame(true); // 动画缓存,取名字 CCAnimationCache::sharedAnimationCache()->addAnimation(animation, "Lightning"); // 获取第一帧 CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("lightning01.png"); // 用第一帧作静态图 CCSprite *first = CCSprite::createWithSpriteFrame(frame); first->setPosition(ccp(100, 100)); this->addChild(first); // 用名字在缓存取帧动画信息 CCAnimation *anim = CCAnimationCache::sharedAnimationCache()->animationByName("Lightning"); // 有动画信息生成动画 CCAnimate *animate = CCAnimate::create(anim); // 执行动画 first->runAction(CCRepeatForever::create(animate));
本来还想做个gif的,mac下的那个软件太贵了,就算了。看个截图