創建不同方向的動畫函數

CCAnimation* createAnimationByDirection(HeroDirection direction)
{
 CCTexture2D *heroTexture = CCTextureCache::sharedTextureCache()->addImage("hero.png");
 CCSpriteFrame *frame0, *frame1, *frame2, *frame3;
 frame0 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(32*0, 32*direction, 32, 32));
 frame1 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(32*0, 32*direction, 32, 32));
 frame2 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(32*0, 32*direction, 32, 32));
 frame3 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(32*0, 32*direction, 32, 32));
 CCArray* animFrames = new CCArray(4);
 animFrames->addObject(frame0);
 animFrames->addObject(frame1);
 animFrames->addObject(frame2);
 animFrames->addObject(frame3);
 CCAnimation* animation = new CCAnimation();
 animation->createWithSpriteFrames(animFrames, 0.2f);   //0.2f表示每幀動畫間的間隔
 animFrames->release();

 return animation;
}

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