目的是要把粒子挂载到骨骼动画的某个一个部件上,其实最主要是找对位置。

预览效果,左手红火,右手蓝火,很炫吧:)

如何给spine骨骼动画挂载粒子特效-LMLPHP

//init

bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
CCSkeletonAnimation* skeletonNode = CCSkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas");
skeletonNode->setAnimation("walk", true);
skeletonNode->setPosition(ccp(,));
//skeletonNode->debugSlots = true;
skeletonNode->debugBones = true;
skeletonNode->timeScale = 0.5f;
addChild(skeletonNode,,); ParticleSun* _emitter1 = ParticleSun::create();
_emitter1->setTexture( TextureCache::getInstance()->addImage("fire.png") );
addChild(_emitter1, , ); ParticleGalaxy* _emitter2 = ParticleGalaxy::create();
_emitter2->setTexture( TextureCache::getInstance()->addImage("fire.png") );
skeletonNode->addChild(_emitter2, , ); scheduleUpdate(); return true;
}

//update

void HelloWorld::update (float deltaTime)
{
CCSkeletonAnimation* skeletonNode = (CCSkeletonAnimation*)getChildByTag(); Bone* pBone = skeletonNode->findBone("left hand");
CCPoint pt = skeletonNode->convertToWorldSpace(ccp(pBone->worldX,pBone->worldY));//粒子1是添加在Scene上的 所以需要坐标转换一下
ParticleSun* _emitter1 = (ParticleSun*)getChildByTag();
_emitter1->setPosition(pt); pBone = skeletonNode->findBone("right hand");
pt = ccp(pBone->worldX,pBone->worldY);//粒子2直接挂到骨骼动画上,所以不需要转换坐标
ParticleGalaxy* _emitter2 = (ParticleGalaxy*)skeletonNode->getChildByTag();
_emitter2->setPosition(pt);
}
05-11 13:16