存储动画
读取动画
记得先让精灵停止当前动画再执行新的动画
完整的CODE
CCSpriteFame *sprite1 = CCSpriteFrame::create("/helloworld1.png", CCRectMake(0,0,100,100)); CCSpriteFame *sprite2 = CCSpriteFrame::create("/helloworld2.png", CCRectMake(0,0,100,100)); CCArray *frame = CCArray::create(sprite1,sprite2,NULL); CCAnimation *animation = CCAnimation::create(frame,1.0f); CCAnimationCache::shareAnimationCache()->addAnimation(animation, "moveUp");
读取动画
CCAnimation *moveUp = CCAnimationCache::shareAnimationCache()->animationByName("moveUp"); CCSprite *sprite = CCSprite::create(); this->addChild(sprite); sprite->runAction(CCRepeatForever::create(CCAnimate::create(moveUp)));
记得先让精灵停止当前动画再执行新的动画
sprite->stopAllActions();
完整的CODE
CCArray *arr = CCArray::create(); for (int i = 1; i < 5; i++) { CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(CCString::createWithFormat("image 29%d.png", i)->getCString()); arr->addObject(frame); } CCAnimation *anim = CCAnimation::createWithSpriteFrames(arr, .1f); CCAnimationCache::sharedAnimationCache()->addAnimation(anim, "walk");