cocos2d-x中创建帧动画

来源:互联网 发布:c语言建立加密后的文件 编辑:程序博客网 时间:2024/05/30 23:36

            下面直接贴相关代码:

(1)使用了TexturePack工具打包组合图片,稍后贴出改工具的下载和用法。

// boss军队动画CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("battle/boss_jundui.png");// Animation using Sprite BatchNodeCCSprite* sprite = CCSprite::createWithSpriteFrame(CCSpriteFrame::createWithTexture(texture, CCRectMake(150*0, 100*0, 150, 100)));sprite->setPosition(ccp(position2_1[11][0],position2_1[11][1]));this->addChild(sprite);// manually add frames to the frame cacheCCArray* animFrames = CCArray::createWithCapacity(37);for (int i=0; i<=36; i++){CCSpriteFrame *frame = CCSpriteFrame::createWithTexture(texture, CCRectMake(150*(i%6), 100*(i/6), 150, 100));animFrames->addObject(frame);}CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1f);CCAnimate *animate = CCAnimate::create(animation);sprite->runAction(CCRepeatForever::create(animate));


 

(2)用了TexturePack工具、AnimatePacker工具

// 使用AnimatePacker工具(和该版本(2.0.3)有冲突,目前还没改好,不能使用)/*AnimatePacker::getInstance()->loadAnimations("battle/boss_jundui.xml"); CCSprite *sprite=CCSprite::createWithSpriteFrameName("battle/boss_jundui.pngg"); sprite->setAnchorPoint(CCPointZero);sprite->setPosition(ccp(winSize.width/2, winSize.height/2)); sprite->runAction(CCRepeatForever::create(AnimatePacker::getInstance()->getAnimate("animFrames2"))); this->addChild(sprite,1); */


 

(3)用一张张单独动画图片

原创粉丝点击