CCSize size=CCDirector::sharedDirector()->getWinSize(); //第一步:生成动画需要的数据 CCTexture2D *texture=CCTextureCache::sharedTextureCache()->addImage("number.png"); //CCRectMake(x,y,width,height) //x,y是起点,左上角为(0,0) CCSpriteFrame *frmae0=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*0,12,16)); CCSpriteFrame *frmae1=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*1,12,16)); CCSpriteFrame *frmae2=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*2,12,16)); CCSpriteFrame *frmae3=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*3,12,16)); CCArray *animFrames = CCArray::create(); animFrames->addObject(frmae0); animFrames->addObject(frmae1); animFrames->addObject(frmae2); animFrames->addObject(frmae3); //创建帧序列 CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames,2.0f); animFrames->release(); //第二步:初始化并设置Sprite CCSprite *sprite =CCSprite::createWithSpriteFrame(frmae0); sprite->setPosition(ccp(size.width/2,size.height/2)); addChild(sprite); //第三步:使用animation生成一个动画动作animate CCAnimate *animate = CCAnimate::create(animation); sprite->runAction(CCRepeatForever::create(animate));//重复播放