创建不同方向的动画函数

来源:互联网 发布:灵界室友网络剧 编辑:程序博客网 时间:2024/05/04 12:16

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;
}