cocos2d-x中创建帧动画

            下面直接贴相关代码:

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

// boss军队动画
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("battle/boss_jundui.png");

// Animation using Sprite BatchNode
CCSprite* 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 cache
CCArray* 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)用一张张单独动画图片

你可能感兴趣的:(cocos2d-x中创建帧动画)