cocos2d-x學得有點蛋疼,,記一下動畫的幾個函數

照着教程扒代碼,,發現版本不一樣,函數有略微差別。  

折騰完之後來記錄一下。

版本: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));


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章