一、序列帧动画
可以先使用TexturePacker将很多序列帧图片拼成一张大图,在构造函数中使用
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("plane.plist","plane.png");
将资源加载到内存中,
在析构函数中使用
CCSpriteFrameCache::sharedSpriteFrameCache()->removeSpriteFramesFromFile("plane.plist");释放资源
序列帧的播放:
CCArray * array = CCArray::create();
for(int i=1;i<=2;i++)
{
char temp[15];
sprintf(temp,"plane_0%d.png",i);
CCSpriteFrame * frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(temp);
array->addObject(frame);
}
CCAnimation * animation = CCAnimation::createWithSpriteFrames(array,0.1f);
plane -> runAction(CCRepeatForever::create(CCAnimate::create(animation)));
精灵这个时候也可以通过内存中的资源来创建
plane = CCSprite::createWithSpriteFrameName("plane_01.png");
二、普通动画
移动动作:CCMoveBy CCMoveTo
旋转动作:CCRotateBy CCRotateTo
缩放动作:CCScaleBy CCScaleTo
跳跃动作:CCJumpBy CCJumpTo
淡入淡出动作:CCFadeBy CCFadeIn CCFadeOut
CCMoveTo * moveTo =CCMoveTo::create(0.5f,CCPointMake(400,400));
CCMoveTo * moveBack =CCMoveTo::create(0.5f,CCPointMake(200,200));
//sprite->runAction(moveTo);使用方法一
//sprite->runAction(CCSequence::create(moveTo,moveBack,NULL));//使用方法二(依次执行moveTo,moveBack)
//sprite->runAction(CCRepeat::create(CCSequence::create(moveTo,moveBack,NULL),2));//重复执行两次
sprite->runAction(CCRepeatForever::create(CCSequence::create(moveTo,moveBack,NULL)));//一直重复执行