Cocos2d-x 2.1.5 简单动画
Cocos2d新版本函数更改了一些。
下面的代码可以产生一个简单动画。
//第一步:生成动画需要的数据 CCTexture2D *texture=CCTextureCache::sharedTextureCache()->addImage("image.png"); CCSpriteFrame *frmae0=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*0,48*0,32,48)); CCSpriteFrame *frmae1=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*1,48*0,32,48)); CCSpriteFrame *frmae2=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*2,48*0,32,48)); CCSpriteFrame *frmae3=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*3,48*0,32,48)); CCArray *animFrames = CCArray::create(); animFrames->addObject(frmae0); animFrames->addObject(frmae1); animFrames->addObject(frmae2); animFrames->addObject(frmae3); CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames,0.2f); animFrames->release(); //第二步:初始化并设置Sprite CCSprite *sprite =CCSprite::createWithSpriteFrame(frmae0); sprite->setPosition(ccp(s.width/2,s.height/2)); addChild(sprite); //第三步:使用animation生成一个动画动作animate CCAnimate *animate = CCAnimate::create(animation); sprite->runAction(CCRepeatForever::create(animate));//重复播放