照着教程扒代码,,发现版本不一样,函数有略微差别。
折腾完之后来记录一下。
版本:cocos2d-2.1rc0-x-2.1.2
1.建立纹理
CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage("xxx.yyy");
2.用纹理构造每一帧
CCSpriteFame *frame0 = CCSpriteFrame::createWithTexture(pTexture, CCRectMake(x, y, width, height));
.........
CCSpriteFame *framen = CCSpriteFrame::createWithTexture(pTexture, CCRectMake(x, y, width, height));
3.将帧封装成CCArray
CCArray *pArray = CCArray::create();
pArray->addObject(frame0);
.........
pArray->addObject(framen);
4.用CCArray构造CCAnimation
CCAnimation *animation = CCAnimation::createWithSpriteFrames(pArray, xx.xf);
CC_BREAK_IF(!animation);
5.初始化一个精灵
CCSprite *girlSprite = CCSprite::createWithSpriteFrame(frame0);
CC_BREAK_IF(!girlSprite);
girlSprite->setPosition(ccp(x, y);
this->addChild(girlSprite, 2);
6. 将CCAnimation构造成CCAnimate,使精灵可以执行此动作
CCAnimate *animate = CCAnimate::create(animation);
CC_BREAK_IF(!animate);
7. 精灵执行相应动作
girlSprite->runAction(CCRepeatForever::create(animate));